Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » Django
  • » Problema con ForeignKeys hacia una tabla abstracta [RSS Feed]

#1 Dec. 1, 2010 11:58:56

F.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Problema con ForeignKeys hacia una tabla abstracta


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Buenas tardes a todos;

Quiero tener ForeignKeys hacia el modelo padre en las tablas intermedias
(manytomany trough) para tener entradas únicas en las mismas.

El problema es que quiero que este modelo padre sea abstract, ya que
nunca querré instanciarlo, utilizando DomainOwned o DomainPending en vez
de esta.

El error que tengo es este:

File "/home/ferran/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

En las foreignkeys a DomainUbi, tanto en ContactType como en
AssociatedNameServer.

Había pensado que podría implementar los fields ns y contacts en ambas
tables (DomainOwned y DomainPending), utiliando generic relationships,
pero no me parece correcto.

Alguien me puede echar una mano?
- ---

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=)

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=
)
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/iQIcBAEBCAAGBQJM9jhAAAoJEAWOKfEESaOwaOgP/36oNmwpYoYkqhuYYuR53Vge
YnIAnMoEIJIze9V4zJhDDWGcvRy8cjz86oqdLQ6Qg3BA+1JxrYML3GY4BWAAslrB
SAPKNfSjP5zspNdfEHrmnq1/bEQnqeeRor5AmfyXUhMBWdE26cCiMWgZVE+M6L6i
+jMku/50COW4JUk55mOE54KdicQ5ChCCWBv1G3aP9mBoMkKQLkLAvTK4DY+bv2xm
vWxXdyjKTGjF5Ck8JSXtq4N7rJev68eoTaK+lc392vkqTrQOrOgDan60hoiej8Dk
cr0ITh9fQuIV59tbL2Bf8vYK8OR3yWoVdL+lfw6xbdovq4qVpjDj01ZN3a42+Mvx
0HFJfnGUhu6zlK1LZWAayIGS+bDnwbvIDkVcx5GxnmQYM9jomMojiirhGttx6mlc
zMPXRzFAw2YyWtFYpSn2bA4e42G83sssRqaQlVdNeGFzP6I4Y67I5TDrPgd1tTKJ
QyC1eFNRxhfoRcYVfYMoTSFBd2FLpLPzMb3cNm3GOeasEgxlj3p1nBErljCdBl2w
jyMLE4/bov63szC78iThMuyV+AxO8ENmLe+NRkHMMToHp6eoyikZR9jRhcAJN0nG
UoQObbeRtNBeko63qwykWOHJgZ+zrkRIk2X3rfbHiW0zXcsWXXBReE+eO7mWIbdY
CrByJHKi89DUea6mUtQ4
=S6Gj
-----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-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#2 Dec. 1, 2010 12:00:09

F.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Problema con ForeignKeys hacia una tabla abstracta


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

On 01/12/10 12:57, Ferran wrote:
> Buenas tardes a todos;

Sorry list, this mail was intended to a spanish django list.

Ignore this mail, thanks.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla -http://enigmail.mozdev.org/iQIcBAEBCAAGBQJM9jiJAAoJEAWOKfEESaOw5X8P/2xbRhGXX0AtpGsLbRtve+Y8
eFlPZgBucOdBNU+wVN3EEE3bfBUv5tY4LK0TKYb4OnWbYsfhi3TW2AmKiBfchPYV
KK19fVh7fyRawsTtmSWvxG8q29i+2DFNvc3mgG8UdJMAuImbxz2tOIvR6p7y2XPI
RfSk4H5pRvC7jtZ/lbHU05PSHw4odoT0+0tOa2ZQIJ42uJvfIViMi90P9HEVhhiP
MpM+jus4YJfkRxqDMS9t/6D+4epnXnS5jiuS8KUsWzJL2V7UbhyoRVWrqr3GavKS
oHxCeufcRaXrcNhob3Zo0sHSvq194SPHZBQt0RFjjuz5ZACOHERDVfyjsNlGLo8L
JyWNhRSoh4SY5UntQnkPzN8Ol+cNY+TP7TLO6ENjDNLI7hxwyarms78gwtIiOtDp
AkboZUy2BpbzqcVBMvnpH2YnWAAoCNiQ2qjb1Nm3LtlGYRbseOsT8Iu3Ofl0tWLZ
LLfBCUQvzzJN3H5yqtSHRbbEq0oNBot52P05UL6gYbX+wMl6hs0xjqq65567uOQT
G2kugUZ8BRcWZv/oyCZ8Agd2lOn8VZ4zR3/KFlvE+h9eh6upme7PupF/RYUEBuS/
//XyQs092q80xfdqFQaGpv3GVA5KG71LKvc4KdChCrg4aGRzjIGZR9wxBizhvLHT
zaEUbvFDcljczp6Z3eEy
=v/YG
-----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-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

  • Root
  • » Django
  • » Problema con ForeignKeys hacia una tabla abstracta [RSS Feed]

Board footer

Moderator control

Enjoy the 17th of August
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support