0

I have objects and catetories in Django and object has ForeignKey to Category.

In Admin user must first create categories and then create objects choosing category from list.

What I want to have is file manager metaphore: User opens list of categories, clicks "create object here" and creates one like we do it with folders and files.

I wonder if Django has some application for it. Does it?

I know about inlines, but I do not want to edit object on the same page, I want to have list of them.

It is similar to Django: adding an "Add new" button for a ForeignKey in a ModelForm but I do not have ModelForm, I speak about admin

user996142
  • 2,753
  • 3
  • 29
  • 48
  • Your question is probably going to get closed as too broad or unclear, but I think what you're asking is a duplicate of [Django: adding an "Add new" button for a ForeignKey in a ModelForm](https://stackoverflow.com/questions/28068168/django-adding-an-add-new-button-for-a-foreignkey-in-a-modelform) – solarissmoke Dec 17 '17 at 03:22
  • The admin already does this for you... – solarissmoke Dec 17 '17 at 03:26
  • @solarissmoke could you please give me example how django-admin does it? – user996142 Dec 17 '17 at 11:46

2 Answers2

1

In Django admin, you can use inlines, example:

class OBJECTSInline(admin.TabularInline):
    model = OBJECTS
    extra = 0

class CATEGORYAdmin(admin.ModelAdmin):
    list_per_page = 10
    inlines = [OBJECTSInline,]

admin.site.register(CATEGORY, CATEGORYAdmin)
1

If you register both your models in the Django admin, you will see that when creating/editing an object with foreign key to Category, there will be a dropdown for the foreign key value, which lists existing values, and next to it, buttons for editing/deleting the selected value, or for creating a new Category:

Screenshot of foreign key management utils in Django admin

That seems to be what you're asking for - it's already there in the admin as soon as you register the relevant models.

solarissmoke
  • 30,039
  • 14
  • 71
  • 73