#10075: model inheritance with foreign key problem
----------------------------------------------+-----------------------------
Reporter: [email protected] | Owner: nobody
Status: new | Milestone:
Component: Forms | Version: 1.0
Resolution: | Keywords: model
inheritance foreign key
Stage: Unreviewed | Has_patch: 0
Needs_docs: 0 | Needs_tests: 0
Needs_better_patch: 0 |
----------------------------------------------+-----------------------------
Changes (by ramiro):
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
Old description:
> I have these three models:
>
> class Address(models.Model):
> name = models.CharField(max_length=100)
> ## many other fields ##
>
> class Meta:
> ordering = ('name',)
>
> def __unicode__(self):
> return self.name
>
> class Organization(models.Model):
> name = models.CharField(max_length=100)
> ## many other fields ##
>
> class Meta:
> ordering = ('name',)
>
> def __unicode__(self):
> return self.name
>
> class OrganizationAddress(Address):
> organization = models.ForeignKey (
> Organization,
> related_name = "addresses",
> )
>
> When i try to add/edit an organization and add one address i've got this
> error:
>
> " ValueError: Cannot assign None: "OrganizationAddress.address_ptr"
> does not allow null values. "
>
> I've tried to understand the problem (because it happened since one day
> to another..) and i've found that the problem was born after the django
> commit of the changeset 9664.
>
> This is the "incriminated code" of changeset:
> 488 if fk_attname == self._pk_field.attname:
> 489 exclude = [self._pk_field.name]
> 490 else:
> 491 exclude = []
>
> I have "organization_id" in the fk_attname e "address_ptr" in the
> self._pk_field.attname and so the primary_key wasn't insert in the
> exclude list.
>
> Below a code portion to test the problem.
>
> """
> from django.forms.models import inlineformset_factory
> from my_apps.models import Organization, Address, OrganizationAddress
>
> Organization(name='test').save()
> org = Organization.objects.get(name='test')
>
> inline_formset = inlineformset_factory(Organization, OrganizationAddress,
> can_delete=False, extra=2)
>
> data = {
> 'addresses-TOTAL_FORMS': '2', # the number of forms rendered
> 'addresses-INITIAL_FORMS': '0', # the number of forms with initial
> data
> 'addresses-0-name': 'Test test',
> }
>
> formset = inline_formset(data, instance=org)
>
> formset.is_valid()
> formset.save()
> """
>
> Sorry for my english.
> Marco M.
New description:
I have these three models:
{{{
class Address(models.Model):
name = models.CharField(max_length=100)
## many other fields ##
class Meta:
ordering = ('name',)
def __unicode__(self):
return self.name
class Organization(models.Model):
name = models.CharField(max_length=100)
## many other fields ##
class Meta:
ordering = ('name',)
def __unicode__(self):
return self.name
class OrganizationAddress(Address):
organization = models.ForeignKey (
Organization,
related_name = "addresses",
)
}}}
When i try to add/edit an organization and add one address i've got this
error:
{{{
" ValueError: Cannot assign None: "OrganizationAddress.address_ptr"
does not allow null values. "
}}}
I've tried to understand the problem (because it happened since one day to
another..) and i've found that the problem was born after the django
commit of the changeset [9664]
This is the "incriminated code" of changeset:
{{{
488 if fk_attname == self._pk_field.attname:
489 exclude = [self._pk_field.name]
490 else:
491 exclude = []
}}}
I have "organization_id" in the fk_attname e "address_ptr" in the
self._pk_field.attname and so the primary_key wasn't insert in the exclude
list.
Below a code portion to test the problem.
{{{
from django.forms.models import inlineformset_factory
from my_apps.models import Organization, Address, OrganizationAddress
Organization(name='test').save()
org = Organization.objects.get(name='test')
inline_formset = inlineformset_factory(Organization, OrganizationAddress,
can_delete=False, extra=2)
data = {
'addresses-TOTAL_FORMS': '2', # the number of forms rendered
'addresses-INITIAL_FORMS': '0', # the number of forms with initial data
'addresses-0-name': 'Test test',
}
formset = inline_formset(data, instance=org)
formset.is_valid()
formset.save()
}}}
Sorry for my english.
Marco M.
Comment:
(edited description, please please use the 'Preview' button when
submitting a ticket)
--
Ticket URL: <http://code.djangoproject.com/ticket/10075#comment:1>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---