1

I have a set of people, I would like to associate to each person a card with personal informations and a list of things to do, this list doesn't have a fix size (it could have one or more fields), the admin is responsible to fill this list.

How can I give to the admin permissions to add extra fields in these cards through the admin page (not coding)? is it possible or do I must use a fixed-size list?

class Admin(models.Model):
        first_name = models.CharField(max_length=50)
        last_name = models.CharField(max_length=50)
        birth_date = models.DateField(blank=True, null=True)
        address = models.CharField(max_length=100, blank=True, null=True)
        city = models.CharField(max_length=50, blank=True, null=True)
        phone_number = models.CharField(max_length=20, blank=True, null=True)
        email = models.EmailField(blank=True, null=True)

        def __unicode__(self):
            return u'%s %s' % (self.first_name, self.last_name)


class Person(models.Model):
    first_name = models.CharField(max_length=50)
    last_name = models.CharField(max_length=50)
    birth_date = models.DateField(blank=True, null=True)
    address = models.CharField(max_length=100, blank=True, null=True)
    city = models.CharField(max_length=50, blank=True, null=True)
    phone_number = models.CharField(max_length=20, blank=True, null=True)
    email = models.EmailField(blank=True, null=True)
    admin = models.ForeignKey(Admin, blank=True, null=True)

    def __unicode__(self):
        return u'%s %s' % (self.first_name, self.last_name)


class Card(models.Model):
    id_number = models.IntegerField(default=0)
    person = models.OneToOneField(Person, primary_key=True)

    def __unicode__(self):
        return unicode(self.id_number)  



class Things_to_do(models.Model):
    name = models.CharField(max_length=50)
    repetitions = models.IntegerField(default=0, blank=True, null=True)
    series = models.IntegerField(default=0, blank=True, null=True)
    executions = models.IntegerField(default=0, blank=True, null=True)
    rest_time = models.IntegerField(default=0, blank=True, null=True)
    card = models.ForeignKey(Card, blank=True, null=True)

    def __unicode__(self):
        return unicode(self.name)
avafab
  • 1,601
  • 3
  • 20
  • 38
  • I don't understand... Why is a `Card` attached to `Things_to_do` and a `Person` is attached to that. Also why are `Admin` and `Person` basically the same model? I feel like your design is the problem here, not the admin page... If you could explain it better, I can try to help. – Ngenator Mar 24 '13 at 00:28
  • Each Person has a card which is filled with a list of things to do by an administrator. Admin must be able to create new cards, modify existing and associate them to persons. Each person can log in and see in a view only his/her own card. Could you suggest a better design? Thank you – avafab Mar 24 '13 at 08:58

1 Answers1

0

You can try to create a custom JSONField: http://djangosnippets.org/snippets/1478/

With a stuff like this, you will be able to store all fields as a dictionnary. Try to look at this : How to store a dictionary in a Django database model's field

Community
  • 1
  • 1
Zulu
  • 8,765
  • 9
  • 49
  • 56
  • strange that there is no way to do that by default on django admin side uh? at this point maybe it is better to use a fixed size list, this snippets seems not so easy to use. – avafab Mar 23 '13 at 00:01