oscarmlage / django-cruds-adminlte

django-cruds is simple drop-in django app that creates CRUD for faster prototyping
BSD 3-Clause "New" or "Revised" License
425 stars 82 forks source link

Related crud #31

Closed luisza closed 7 years ago

luisza commented 7 years ago

Related fields

A common scenario is that you have a model with a foreignkey to other model that is the main of your view so you want to pass the main model as parameter to a crud views to filter and create using it as main reference, and always save the foreignkey with the main model object.

For example In models

class Author(models.Model):
    name=models.CharField(max_length=150)
class Book(models.Model):
    author = models.ForeignKey(Author):
    name=models.CharField(max_length=150)

In views

from cruds_adminlte.crud import CRUDView
class Myclass(CRUDView):
    model = Book
    related_fields = ['autor']

So with this you now have management of author's book.

Warning: We provide all internal references but you need to create the first author to book list|create|update|detail|delete reference.