S_alj
S_alj

Reputation: 447

Django- how to establish relationships between different apps?

(Keep in mind that still a begginer to Django) I've been creating my first Django App for a while now. In it, I have a model that represents a geographical area. This means that each instance of that model has the purpose of representing a different area on the map. This app is OK.

I've added a 2nd app, a reusable app, to my project, called django-forms-builder, that can be found here:

https://github.com/stephenmcd/django-forms-builder

This app allows me to create custom forms, in the Django Admin, that work fine. But they are 'stand-alone'/'separated' from anything from my own app.

I would like to establish some connection, from these forms from the 2nd app, to the area model from my own app, so that, as a result, specific forms can be associated to specific areas on the map.

This is really confusing to me, as I've only ever used a single app. I've read the models.py file in the 'django-forms-builder' app, and they are abstract, so it seems establishing foreign key relationships between models is not doable here, therefore I feel completely lost with no clues to follow on.

So my question is how to establish a relationship between different Django apps? I feel like there might be a Django concept, some idea other than model foreign keys that I could learn to accomplish this, and that I simply don't know about.

Upvotes: 2

Views: 1404

Answers (1)

McAbra
McAbra

Reputation: 2524

You have non-abstract models there.
With those you should be able to bind a form to a specific 'location':

from forms_builder.forms.models import Form


class Location(models.Model):
    ...
    form = models.ForeignKey(Form, related_name='locations')

This way you can create and relate a form to multiple locations (I guess/hope that's what you are after).

Upvotes: 1

Related Questions