To simplify, I have a model, say,
class Parent(models.Model):
field_a = models.CharField(max_length=40)
and another model that holds an image field, that ties itself to a parent instance via foreign key:
class ParentPicture(models.model):
parent = models.ForeignKey(Parent)
picture = models.ImageField(upload_to=upload_path)
is_used = models.BooleanField(default=False)
The original plan was to support multiple pictures for the parent, and only have one in use at any one time, but now, I'd like to have support for just one picture, and include it in the parent model, so that ParentPicture
can be destroyed, and have Parent
look like so:
class Parent(models.Model):
field_a = models.CharField(max_length=40)
picture = models.ImageField(upload_to=upload_path)
I'm unsure of the best way to move the picture
field over to the new model, and include the instances from the ParentPicture
that have the is_used
flag.
Is there a simple way to do this automatically with Django, or would I need to make the change to the Parent
model, migrate the change, then run a script to go through the ParentPicture
model and copy appropriately, and then only after that's been done, remove the ParentPicture
model?
Thanks for any help/advice!
I think there is not an 'automatic' way to move the field, so you could do:
picture
field to Parent
classpicture
field with values in the model ParentPicture
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With