admin.site.register(Question) doesn't work
i am new to Django and python, and i want to start django admin with official exercises
i'm okay with running server. but questions doesn't show up.
my code is :
from django.contrib import admin from .models import Question admin.site.register(Question)
thank you for reading my question
1) You should have a model named Question in your app's models.py file
2)You should run makemigrations and migrate commands
Writing your first Django app, part 7 | Django documentation, Django does a pretty good job of creating a basic admin site using the information from the registered models: Each model has a list of individual� ModelAdmin): fields = ['pub_date', 'question_text'] admin. site. register (Question, QuestionAdmin) You’ll follow this pattern – create a model admin class, then pass it as the second argument to admin.site.register() – any time you need to change the admin options for a model.
Want to have something like this, check out https://docs.djangoproject.com/en/3.0/ref/contrib/admin/ for more info
from django.contrib import admin from .models import Question class QuestionAdmin(admin.ModelAdmin): pass admin.site.register(Question, QuestionAdmin)
The Django admin site | Django documentation, problem: custom apps do not register properly on django's admin site. The funny thing is that: All the models seem to be correctly registered� ModelAdmin): fields = ['pub_date', 'question_text'] admin. site. register (Question, QuestionAdmin) You’ll follow this pattern – create a model admin class, then pass it as the second argument to admin.site.register() – any time you need to change the admin options for a model.
create a Question model class in models.py with the necessary fields then run makemigrations and migrate commands. Example question model is:
class Question(models.Model): question_id = models.AutoField(auto_created=True,primary_key=True) name = models.CharField(max_length=100) def __str__(self): return self.name class Meta: verbose_name_plural="question"
Django Tutorial Part 4: Django admin site, With Django, building an admin interface is a solved problem. (The order of INSTALLED_APPS doesn't matter, but we like to keep things alphabetical In the admin.py in our books app, each call to admin.site.register() simply registers the� Take a few minutes to marvel at all the code you didn’t have to write. By registering the Question model with admin.site.register(Question), Django was able to construct a default form representation. Often, you’ll want to customize how the admin form looks and works.
Django applications don't appear in django admin site., it doesn't change the database in more than one way. 2:32. It did one change to the database, so for. All right, and then admin.site.register(models.Question).
Chapter 6: The Django Admin Site — Django Book 0.1 documentation, The Django admin site¶. One of the most powerful parts of Django is the automatic admin interface. It reads metadata from your models to provide a quick, model-centric interface where trusted users can manage content on your site.
We have to open the admin.py file in the app folder in which our models are. For example, if we have an app named ‘polls’ and we wish to register a model named ‘Question’, then we need to open ‘polls/admin.py’ and import the Question model and write: admin.site.register(Question). This will register our Question model with the admin