Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django model fields not appearing in admin

I have a relatively simple model in my Django project (I should note that the wording is weird in that the app itself is called 'games' and within it the model is Game but I'll change this later):

from django.db import models

class Game(models.Model):
    player_turn = models.IntegerField(),
    game_state = models.BooleanField(),
    rolled = models.BooleanField(),
    rolled_double = models.BooleanField(),
    last_roll = models.IntegerField(),
    test_text = models.CharField(max_length = 200),

with a settings.py file in the main folder of the project showing

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'games.apps.GamesConfig',
]

and games/admin.py looks like this from django.contrib import admin

from .models import Game

admin.site.register(Game)

When I try to run 'python3 manage.py makemigrations' it shows that no changes are detected (even if I arbitrarily change the Game model to test the effect) and when I go into the admin site to add a new game there are no fields available to edit like there are for the User and Group models. The model itself shows up in the admin site but without any fields. Right now I'm following along the MDN Django tutorial (https://developer.mozilla.org/en-US/docs/Learn/Server-side/Django/Models) and it seems like I'm following all of the necessary steps so can someone let me know what I might be forgetting to do?

I'd be happy to post any other code that might be helpful if needed. Images of site admin are below. Thanks in advance.

Main Site AdminGame InfoAdd Game

like image 416
Jeff Avatar asked Jan 12 '18 04:01

Jeff


People also ask

How to Register model in admin Django?

from django. contrib import admin # Register your models here. Register the models by copying the following text into the bottom of the file. This code imports the models and then calls admin.

What is model admin in Django?

The modeladmin module allows you to add any model in your project to the Wagtail admin. You can create customisable listing pages for a model, including plain Django models, and add navigation elements so that a model can be accessed directly from the Wagtail admin.


1 Answers

remove all the commas (',') after each field in the model and try to makemigrations and migrate and then check the admin panel

class Game(models.Model):
    player_turn = models.IntegerField()
    game_state = models.BooleanField()
    rolled = models.BooleanField()
    rolled_double = models.BooleanField()
    last_roll = models.IntegerField()
    test_text = models.CharField(max_length = 200)
like image 191
Exprator Avatar answered Sep 18 '22 19:09

Exprator