Hash: SHA256
Hello everyone,
I want to have foreign keys to parent model on a manytomany
intermediate table (through) to have unique entries for that domain.
The problem is i want this parent model class to be an abstract one,
because i don't ever want to instantiate it, using DomainOwned or
DomainPending instead.
The error i'm getting is this:
File "/home/ferran/0_ubilibet/intranet/domains/models.py", line 48,
in ContactType
domain = models.ForeignKey(DomainUbi)
File
"/usr/lib/python2.7/site-packages/django/db/models/fields/related.py",
line 808, in __init__
assert not to._meta.abstract, "%s cannot define a relation with
abstract class %s" % (self.__class__.__name__, to._meta.object_name)
AssertionError: ForeignKey cannot define a relation with abstract
class DomainUbi
On both the foreignkeys to DomainUbi on models ContactType and
AssociatedNameServer.
I've thought maybe i can implement contacts and ns fields in both
DomainOwned and DomainPending, using generic relationships, but it
does not seems right to me.
Can anyone help me on this, please?
- ---
class DomainMinimal(models.Model):
sld = models.CharField(
max_length=63
)
tld = models.ForeignKey(common.Tld)
name = property('_domain_name')
def _domain_name(self):
return u'%s.%s' % (self.sld, self.tld)
def __unicode__(self):
return self.name
class Meta:
abstract = True
class DomainUbi(DomainMinimal):
owner = models.ForeignKey(contacts.Contact, related_name='Owner')
contacts = models.ManyToManyField(contacts.Contact,
through='ContactType')
ns = models.ManyToManyField('NameServer',
through='AssociatedNameServer')
period = models.IntegerField(validators=[MaxValueValidator(10)])
class Meta:
abstract = True
class DomainOwned(DomainUbi):
crdate = models.DateField()
exdate = models.DateField()
class DomainPending(DomainUbi):
status = None # just an example, now
class ContactType(models.Model):
contact = models.ForeignKey(contacts.Contact)
domain = models.ForeignKey(DomainUbi)
role = models.CharField(
max_length=10,
choices = (
('admin', 'Administratiu'),
('billing', 'Facturacio'),
('tech', 'Tecnic'),
)
)
class Meta:
unique_together = ('contact', 'domain', 'role')
class AssociatedNameServer(models.Model):
ns = models.ForeignKey('NameServer')
domain = models.ForeignKey(DomainUbi)
priority = models.IntegerField(
validators=[MaxValueValidator(4)]
)
def __unicode__(self):
return "%s (%s)" % (self.ns.host, self.ns.ip)
class Meta:
unique_together = ('ns', 'domain', 'priority')
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iQIcBAEBCAAGBQJM9jX2AAoJEAWOKfEESaOw1xIP/2ijO1VOXmnxoT1VdiuilcgP
qK+9YXS7Y6bwIhy9zGHF5QB/wAVQyYbYEA/mpLPP09ShA7LV2qO5ZRsdR0TYChfF
P/mVoz73BSkFQLw+B4rS2XCTfXCzumFEslrqWtSAyNnxU1+LjtT/GpFfxldU3PiF
oNnNbAJSjLdd1OvtIP7I3iquj+AV5iuzSDmi38zL5xT9mF75+hg0TXkcA04KMNKJ
AfvZ3j5ofRHJCwpu1jYtE85OzXWasffJeYvXiPLHGHb/Pdp0WwvFCBTb9nIRwVVR
mt/d5lIp6ATuakCxMz9TDM3wf0+81ynGI9s/csZuY3c0RAlKpkzgYMYARC81haiQ
mKJJgQ9J9IHcry9XcMcOZ+x4j+c5JYvNQx5YI+LAuLdXGqzlmQ9mz3Ur0Jsu9H5I
b1wOSiIqDF6uITjCjqlQL1zrSgPSD1NKSBzSm/LO3bBjEqqZL31K7NNUtN70GGhS
Qb85TxpitLHMBhsPjQhi6248CoL5s3/MkPHC9JHajPa2G6ZT+gR7tCiXnkmURdU6
UO1YelGx751GUTRZQxhBPorNHgMPtYrZ4+fPfGVxWfjG1vXS9WXgs4O+xYaIpnMK
lCmX431JJstDHFERbc48qvnuyvy0QX4J1iRsbVJJ8yjYG8vSRzKSFMksibH+PCHl
5UipC5zZfUyxNWR8/bDS
=nHpW
-----END PGP SIGNATURE-----
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
No comments:
Post a Comment