Hi,

> class A(models.Model):
>     fieldA = models.IntegerField()
>     fieldB = models.IntegerField()
>
> class B(models.Model):
>     fieldA = models.IntegerField()
>     fieldB = models.IntegerField()
>     anotherfieldA = models.IntegerField()
>     anotherfieldB = models.IntegerField()
>
> I want to have something like
>
> class Fields(models.Model):
>     fieldA = models.IntegerField()
>     fieldB = models.IntegerField()
>     class Meta:
>         abstract = True
>
> class A(models.Model):
>     fields = models.ForeignKey(Fields)
>
> class B(models.Model):
>     fields = models.ForeignKey(Fields)
>     anotherfields = models.ForeignKey(Fields)
>
> Is there another way than an abstract class for defining a group of
> fields?

Firstly, your foreign keys to Fields won't work because you can't have
foreign keys to tables that don't exist in the database. Abstract
models are meant to be extended from their classes (i.e. class A
(Fields))

Given your Fields abstract class above, here's one way to define A and
B:

class A(Fields):
        pass

class B(Fields):
        anotherfieldA = models.IntegerField()
        anotherfieldB = models.IntegerField()

-Rajesh D

--~--~---------~--~----~------------~-------~--~----~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to