A
A
alexkomp2019-02-24 19:35:40
Django
alexkomp, 2019-02-24 19:35:40

How to add a service module and a specialist module to the admin panel in python django?

in models.py I wrote the service class and specialists

from django.db import models

class услуги(models.Model):
  title = models.TextField()
  
class Специалисты(models.Model):
  title = models.TextField()

added to urls.py
from django.urls import path, include
from django.views.generic import ListView, DetailView
from news.models import Специалисты, услуги

urlpatterns =[
    path('', ListView.as_view(queryset=услуги.objects.all().order_by("-title")[:20], template_name="news/услуги.html")),
    path('', ListView.as_view(queryset=Специалисты.objects.all().order_by("-title")[:20], template_name="news/специалисты.html")),
  ]

configured and entered the admin panel, entered the values ​​​​for specialists and services, I went to the local server and the text was added to the services, but not to the specialists, I changed the code in the urls.py file to this
from django.urls import path, include
from django.views.generic import ListView, DetailView
from news.models import Специалисты, услуги

urlpatterns =[
    path('', ListView.as_view(queryset=Специалисты.objects.all().order_by("-title")[:20], template_name="news/специалисты.html")),
               path('', ListView.as_view(queryset=услуги.objects.all().order_by("-title")[:20], template_name="news/услуги.html")),
    
  ]

I did it all over again and this time the specialists were full, but there were no services.
What can be done so that both the services and the specialists work on the site ???

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Max Cage, 2019-02-26
@alexkomp

If we figured out the Cyrillic, it should not be in the princepe, then let's move on to the problem.
You have 2 identical patches, django goes to the first one and does not go further. Therefore, only one is displayed. Or specialists or services, whichever comes first.
To display both one and the other, you need to pull them out, for example, in a function.

def you_function(request):
    specialists = Specialists.objects.all()
    services = Services.objects.all()
    data = {'s': specialists, 'services': services}
    return render(request, 'name.html', data')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question