3👍
✅
What about a static method on the class to handle this?
colored = ColoredComic.create_from_Inked(pk=ink_id)
colored.colored = True
colored.save()
Untested, but something to this effect (using your code from above)
class ColoredComic(Comic):
colored = models.BooleanField(default=False)
@staticmethod
def create_from_Inked(**kwargs):
inked = InkedComic.objects.get(**kwargs)
if inked:
colored = ColoredComic.objects.create()
colored.__dict__.update(inked.__dict__)
colored.__dict__.update({'id': None}) # Remove pk field value
return colored
else:
# or throw an exception...
return None
0👍
For that simple case, this will work:
inked = InkedComic.object.get(pk=ink_id)
inked.__class__ = ColoredComic
inked.colored = True
inked.save()
- [Django]-[django]when debug=false,MEDIA_URL returns not found
- [Django]-Login/check the username and password from database in Django website using post request
- [Django]-Django MEDIA_URL returns http instead of https
- [Django]-How do I move project folders in PyCharm Project View?
- [Django]-Python Asynchronous Reverse DNS Lookups
Source:stackexchange.com