Cant Understand The topic

I cant seem to understand The django part on the 6hrs course free on YT and im stuck there any help please??

What specific django part do you not understand?

i’ll just say from the beginning the django course started on the 6hr YT free course

I keep having this error whenever i want to add a new product to my django admin

Help Im stuck with the django admin Stuff
i was trying to add product through the django admin and it just pop up with some code error

Hi see this thread you may need to upgrade your version of django

i already found a way to do that now im stuck with another problem

Feel free to post a screenshot of the error you are facing

I already got over the problem I just had upgrade my django version then run server and migrate

Now im facing another issue with this"
ERRORS:
<class ‘products.admin.OfferAdmin’>: (admin.E108) The value of ‘list_display[0]’ refers to ‘offer’, whi
ch is not a callable, an attribute of ‘OfferAdmin’, or an attribute or method on ‘products.Offer’.

WARNINGS:
products.Offer: (models.W042) Auto-created primary key used when not defining a primary key type, by de
fault ‘django.db.models.AutoField’.
HINT: Configure the DEFAULT_AUTO_FIELD setting or the ProductsConfig.default_auto_field attribu
te to point to a subclass of AutoField, e.g. ‘django.db.models.BigAutoField’.
products.Product: (models.W042) Auto-created primary key used when not defining a primary key type, by
default ‘django.db.models.AutoField’.
HINT: Configure the DEFAULT_AUTO_FIELD setting or the ProductsConfig.default_auto_field attribu
te to point to a subclass of AutoField, e.g. ‘django.db.models.BigAutoField’.

System check identified 3 issues (0 silenced)." thats the issue

Check the value of list_display in your OfferAdmin class there is something malformed there

ie:

# products/admin.py

class OfferAdmin(admin.ModelAdmin):
    list_display = ('check_this', 'other_field', ...)

where it says check this, make sure the syntax is right

The other one is a warning and your code will run

The syntax is correct there is no error in the value in list_display
This is the code "from django.contrib import admin

from . models import Product, Offer

class OfferAdmin(admin.ModelAdmin):
list_display = (‘Code’, ‘discount’ )

class ProductAdmin(admin.ModelAdmin):
list_display = (‘name’, ‘price’,‘stock’ )

admin.site.register(Offer, OfferAdmin)
admin.site.register(Product, ProductAdmin)"

So Far no error

I was stuck with this before File “”, line 219, in _call_with_frames_removed
File “C:\Users\Admin\Desktop\Afresh\products\admin.py”, line 3, in
from . models import Product, Offer
ImportError: cannot import name ‘Offer’ from ‘products.models’ (C:\Users\Admin\Desktop\Afresh\products
models.py)
then i called an offer class in models then the error stopped with 0 issues
after Calling the class it started with 3 issues

list_display = (‘Code’, ‘discount’ )

here code is uppercase, but mosh saves as lower case in the model and in admin

ImportError: cannot import name ‘Offer’ from ‘products.models’

check the models file is in the same folder as your admin file and the naming is the same

Even after calling it in the model like this “class offer(models.Model):
code = models.CharField
discount = models.CharField”
Still dosent work

Change ‘offer’ to ‘Offer’ so looks like below because your importing into your admin file as ‘Offer’ so you need to name your class the same

class Offer(models.Model):
   code = models.CharField
   discount = models.CharField”

Bro still getting the same error 3issues

ok its easier if you post your code and the errors you receiving if you can

MY ADMIN code" from django.contrib import admin
from . models import Product, Offer

class OfferAdmin(admin.ModelAdmin):
list_display = (‘code’, ‘Discount’)

class ProductAdmin(admin.ModelAdmin):
list_display = (‘name’, ‘price’,‘stock’ )

admin.site.register(Offer, OfferAdmin)
admin.site.register(Product, ProductAdmin)"

My Model code :
from django.db import models

class Product(models.Model):
name = models.CharField(max_length=255)
price = models.FloatField()
stock = models.IntegerField()
image_url = models.CharField(max_length=2083)

class Offer(models.Model):
code = models.CharField
discount = models.CharField

The Error
WARNINGS:
products.Offer: (models.W042) Auto-created primary ke
y used when not defining a primary key type, by defau
lt ‘django.db.models.AutoField’.
HINT: Configure the DEFAULT_AUTO_FIELD settin
g or the ProductsConfig.default_auto_field attribute
to point to a subclass of AutoField, e.g. ‘django.db.
models.BigAutoField’.
products.Product: (models.W042) Auto-created primary
key used when not defining a primary key type, by def
ault ‘django.db.models.AutoField’.
HINT: Configure the DEFAULT_AUTO_FIELD settin
g or the ProductsConfig.default_auto_field attribute to point to a subclas
s of AutoField, e.g. ‘django.db.models.BigAutoField’.

System check identified 3 issues (0 silenced).
This is the whole thing

Make sure you have this line in your settings.py file

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

You need to also specify a max_length parameter for your Charfields ie:

class Offer(models.Model):
    code = models.CharField(max_length=255)  # Specify the max length for CharField
    discount = models.CharField(max_length=255)  # Specify the max length for CharField

be sure to double check your indentation is also applied properly after the colon in your classes

Where exactly in the settings.py file should it be