Hello,

I have problems with a OneToOneRelation in this simple model.
Without Inline in the admin.py it basically works, but when I add an Inline 
for the Address to the Resort, I get error messages like:

<class 'testApp.admin.AddressInline'>: (admin.E202) 'testApp.Address' has 
no ForeignKey to 'testApp.Resort'.

I think that I followed the examples from the tutorial quite closely and 
that a foreign key definition on the Address 'returning' to the Resort 
should not be required. Other addresses might/will be owned by other 
objects/classes.

Obviously I must be doing something wrong :-( Any suggestions?

Thanks, Richard


from django.db import models
from django.utils.translation import ugettext_lazy as _

class Address(models.Model):
    number = models.PositiveIntegerField(_('Adress Nr'))
    function = models.CharField(_('Adressfunktion'), max_length=2)
    name = models.CharField(_('Name'), max_length=64)
    street = models.CharField(_('Strasse und Hausnummer'), max_length=64)
    city = models.CharField(_('Ort'), max_length=64)
    postal_code = models.CharField(_('PLZ'), max_length=10)
    phone = models.CharField(_('Telefon'), max_length=32)
    fax = models.CharField(_('Fax'), max_length=32)

    def __str__(self):
        return '%s (%i)' % (self.name, self.number)

    class Meta:
        unique_together = ('number', 'function')
        ordering = ['number', 'function']
        verbose_name = _('Adresse')
        verbose_name_plural = _('Adressen')


class Resort(models.Model):
    base_address = models.OneToOneField(Address, 
verbose_name=_('Resortadresse'), primary_key=True)
    description = models.CharField(_('Bezeichnung'), max_length=64)
    short_description = models.CharField(_('Kurzbezeichnung'), max_length=20)
    sihot_nr = models.PositiveSmallIntegerField(_('Sihot Nr'), unique=True)
    resort_type = models.CharField(_('Resorttype'), max_length=1)



Admin:

from django.contrib import admin
from testApp.models import Address, Resort

class AddressInline(admin.StackedInline):
    model = Address
    extra = 1

class ResortAdmin(admin.ModelAdmin):
    inlines = [AddressInline]

@admin.register(Resort)
class ResortAdmin(admin.ModelAdmin):
    inlines = [AddressInline]


If I register the Address and the Resort class, it gets worse:
<class 'testApp.admin.AddressInline'>: (admin.E202) 'testApp.Address' has 
no ForeignKey to 'testApp.Address'.
<class 'testApp.admin.AddressInline'>: (admin.E202) 'testApp.Address' has 
no ForeignKey to 'testApp.Resort'.

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/a985353c-84b7-4815-97cf-6a1707573691%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to