James,
I just found what I was looking for. It looks like Model.validate_unique() is the test that I am looking for.
Jim
On Tuesday, May 23, 2017 at 6:44:01 PM UTC-4, jjander...@gmail.com wrote:
I have a model class, 'A_base', and a 2nd model class, 'A_derived'. When I save an object of A_derived, I want the data from both my base and derived class to be saved.
Example code looks like this:
class A_base(models.model):
name = models.CharField(max_length=50)
class A_derived(A_base):
role = models.CharField(max_length=50)
So when I call save(), I want to save an instance of the derived object, including the data in the base class into my sqlite3 database. I would like my code to look like this:
...
derived_obj = A_derived.objects.get(name="john")
derived_obj.role = "parent"
derived_obj.save()
...
My question is whether the save method will save 'role' to the A_derived table and save 'name' to the A_base table? Or do I have to override the save method so that it saves 'role' and then calls the base class save method to save 'name'?
I tried doing this using the default save method and it created a stack trace, so I'm guessing that I am expecting too much from the default save method.
Jim A.
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/0ac4ad91-f25a-47ab-afba-d93356697387%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment