Django admin site does not display ManyToManyField relationship

I am working on what, in my opinion, is a pretty standard django site, but I am having trouble getting my admin section to display the correct fields.

Here are my models.py:

class Tech(models.Model):
    name = models.CharField(max_length = 30)

class Project(models.Model):
    title = models.CharField(max_length = 50)
    techs = models.ManyToManyField(Tech)

In other words, a project can have different Tech objects, and different technical objects can belong to different projects (Project X was created using Python and Django, Project Y was C # and SQL Server)

However, the admin site does not display any user interface for Tech objects. Here is my admin.py:

class TechInline(admin.TabularInline):
    model = Tech
    extra = 5

class ProjectAdmin(admin.ModelAdmin):
    fields = ['title']
    inlines = []
    list_display = ('title')

admin.site.register(Project, ProjectAdmin)

I tried to add the class TechInlineto the list inlines, but that calls

<class 'home.projects.models.Tech'> has no ForeignKey to <class 'home.projects.models.Project'>

Error. Also tried adding techsto the list fields, but it gives

no such table: projects_project_techs

. , projects_project_techs, projects_tech. , - syncdb?

Sqlite , .

+3
3

TechInline ,

"TechInLine"

-? , - TechInline TechInline.

syncdb , . :

python manage.py sqlreset <myapp>

projects_project_techs. .

+2

, "", project_tech, project_project.

" " - projects_project_techs

0

@ - sqlreset, . sqlreset , , projects_project_techs . deb.db . techs , .

, , admin.site.register(Tech), .

, , , ( , ), .

0

Source: https://habr.com/ru/post/1697797/


All Articles