I am new to django and building a kinda of a package (Shipments) based app in Django and I have these models,
class ShippingLocation(models.Model):
latitude = models.IntegerField()
longitude = models.IntegerField()
class Shipping (models.Model):
email = models.EmailField()
location = models.ForeignKey(ShippingLocation , default=None, on_delete=models.CASCADE )
class Package(models.Model):
name = models.CharField(max_length=30)
supplier = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.DO_NOTHING)
to = models.ForeignKey(Shipping, default=None, on_delete=models.CASCADE )
this work okay for now but I wonder if can be able to remove the ShippingLocation
model and use a custom field instead of at the location field in the Shipping model? If yes how do I create custom fields and how do I implement them?
so I have something like
class Shipping (models.Model):
email = models.EmailField()
location = models.DictionaryField()
and I get rid of the ShippingLocationModel
I guess you wanted to migrate your existing data from ShippingLocation into Shipping. If you are just on dev, simply delete your sqlite3 file and change to your models to your expectation.
If you are already on prod, I usually do this:
This should be work:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.