A
A
Andrey Grinevich2017-03-16 10:31:11
Django
Andrey Grinevich, 2017-03-16 10:31:11

How to properly define relationships in Django models?

Good day I'm struggling
with the following task:
In the django admin panel, you need to combine two models in such a way as to create an Action independently (the usual creation of a record). After that, it was possible to create a bundle and attach existing Actions to it. Also provide links so that you can find out by query which bundle the current Action has already been attached to.

class Action(models.Model):
    id = models.AutoField(primary_key=True)
    slug = models.CharField(max_length=TYPE_MAX_LENGTH)

    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)

    def __unicode__(self): return self.slug

    class Meta(object):
        db_table = 'actions'


class Bundle(models.Model):
    name = models.CharField(max_length=TYPE_MAX_LENGTH)

    active = models.BooleanField(default=False)

    def __unicode__(self): return self.name

    class Meta(object):
        db_table = 'bundle'

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
devalone, 2017-03-16
@devalone

Apparently you need ForeignKey in Bundle

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question