# Cant Understand The topic

**URL:** https://forum.codewithmosh.com/t/cant-understand-the-topic/24752
**Category:** Django
**Created:** [January 24, 2024, 11:26pm UTC](https://forum.codewithmosh.com/t/cant-understand-the-topic/24752 "2024-01-24T23:26:49Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![Energy](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/energy/32/7669_2.png) [@Energy](https://forum.codewithmosh.com/u/Energy)
#### Post date: [January 24, 2024, 11:26pm UTC](https://forum.codewithmosh.com/t/cant-understand-the-topic/24752/1 "2024-01-24T23:26:49Z")

</div>

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

---

<div class="post-metadata">

### Author: ![lucidlear](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/lucidlear/32/5477_2.png) [@lucidlear](https://forum.codewithmosh.com/u/lucidlear)
#### Post date: [January 24, 2024, 11:30pm UTC](https://forum.codewithmosh.com/t/cant-understand-the-topic/24752/2 "2024-01-24T23:30:52Z")

</div>

What specific django part do you not understand?

---

<div class="post-metadata">

### Author: ![Energy](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/energy/32/7669_2.png) [@Energy](https://forum.codewithmosh.com/u/Energy)
#### Post date: [January 24, 2024, 11:37pm UTC](https://forum.codewithmosh.com/t/cant-understand-the-topic/24752/3 "2024-01-24T23:37:30Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Energy](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/energy/32/7669_2.png) [@Energy](https://forum.codewithmosh.com/u/Energy)
#### Post date: [January 25, 2024, 9:28am UTC](https://forum.codewithmosh.com/t/cant-understand-the-topic/24752/4 "2024-01-25T09:28:39Z")

</div>

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

 ![20240125_102447](https://us1.discourse-cdn.com/flex020/uploads/codewithmosh/original/2X/0/0e49e576a94e5618004cc9d1e137252fcb7f2e38.jpeg)

---

<div class="post-metadata">

### Author: ![Energy](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/energy/32/7669_2.png) [@Energy](https://forum.codewithmosh.com/u/Energy)
#### Post date: [January 25, 2024, 11:08am UTC](https://forum.codewithmosh.com/t/cant-understand-the-topic/24752/5 "2024-01-25T11:08:56Z")

</div>

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

---

<div class="post-metadata">

### Author: ![lucidlear](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/lucidlear/32/5477_2.png) [@lucidlear](https://forum.codewithmosh.com/u/lucidlear)
#### Post date: [January 25, 2024, 7:09pm UTC](https://forum.codewithmosh.com/t/cant-understand-the-topic/24752/6 "2024-01-25T19:09:01Z")

</div>

Hi see this [thread](https://forum.codewithmosh.com/t/no-such-table-main-auth-user-old/2415) you may need to upgrade your version of django

---

<div class="post-metadata">

### Author: ![Energy](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/energy/32/7669_2.png) [@Energy](https://forum.codewithmosh.com/u/Energy)
#### Post date: [January 25, 2024, 8:51pm UTC](https://forum.codewithmosh.com/t/cant-understand-the-topic/24752/7 "2024-01-25T20:51:40Z")

</div>

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

---

<div class="post-metadata">

### Author: ![lucidlear](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/lucidlear/32/5477_2.png) [@lucidlear](https://forum.codewithmosh.com/u/lucidlear)
#### Post date: [January 25, 2024, 9:00pm UTC](https://forum.codewithmosh.com/t/cant-understand-the-topic/24752/8 "2024-01-25T21:00:54Z")

</div>

> [@Energy](#):
>
> 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

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

---

<div class="post-metadata">

### Author: ![Energy](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/energy/32/7669_2.png) [@Energy](https://forum.codewithmosh.com/u/Energy)
#### Post date: [January 25, 2024, 9:04pm UTC](https://forum.codewithmosh.com/t/cant-understand-the-topic/24752/9 "2024-01-25T21:04:29Z")

</div>

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

---

<div class="post-metadata">

### Author: ![lucidlear](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/lucidlear/32/5477_2.png) [@lucidlear](https://forum.codewithmosh.com/u/lucidlear)
#### Post date: [January 25, 2024, 9:11pm UTC](https://forum.codewithmosh.com/t/cant-understand-the-topic/24752/10 "2024-01-25T21:11:25Z")

</div>

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

ie:

```auto
# 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

---

<div class="post-metadata">

### Author: ![Energy](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/energy/32/7669_2.png) [@Energy](https://forum.codewithmosh.com/u/Energy)
#### Post date: [January 25, 2024, 9:15pm UTC](https://forum.codewithmosh.com/t/cant-understand-the-topic/24752/11 "2024-01-25T21:15:44Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Energy](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/energy/32/7669_2.png) [@Energy](https://forum.codewithmosh.com/u/Energy)
#### Post date: [January 25, 2024, 9:18pm UTC](https://forum.codewithmosh.com/t/cant-understand-the-topic/24752/12 "2024-01-25T21:18:56Z")

</div>

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

---

<div class="post-metadata">

### Author: ![lucidlear](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/lucidlear/32/5477_2.png) [@lucidlear](https://forum.codewithmosh.com/u/lucidlear)
#### Post date: [January 25, 2024, 9:26pm UTC](https://forum.codewithmosh.com/t/cant-understand-the-topic/24752/13 "2024-01-25T21:26:03Z")

</div>

`list_display = (‘Code’, ‘discount’ )`

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

```auto
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

---

<div class="post-metadata">

### Author: ![Energy](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/energy/32/7669_2.png) [@Energy](https://forum.codewithmosh.com/u/Energy)
#### Post date: [January 25, 2024, 9:33pm UTC](https://forum.codewithmosh.com/t/cant-understand-the-topic/24752/14 "2024-01-25T21:33:32Z")

</div>

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

---

<div class="post-metadata">

### Author: ![lucidlear](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/lucidlear/32/5477_2.png) [@lucidlear](https://forum.codewithmosh.com/u/lucidlear)
#### Post date: [January 25, 2024, 9:54pm UTC](https://forum.codewithmosh.com/t/cant-understand-the-topic/24752/15 "2024-01-25T21:54:38Z")

</div>

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

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

```

---

<div class="post-metadata">

### Author: ![Energy](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/energy/32/7669_2.png) [@Energy](https://forum.codewithmosh.com/u/Energy)
#### Post date: [January 25, 2024, 10:24pm UTC](https://forum.codewithmosh.com/t/cant-understand-the-topic/24752/16 "2024-01-25T22:24:07Z")

</div>

Bro still getting the same error 3issues

---

<div class="post-metadata">

### Author: ![lucidlear](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/lucidlear/32/5477_2.png) [@lucidlear](https://forum.codewithmosh.com/u/lucidlear)
#### Post date: [January 25, 2024, 10:30pm UTC](https://forum.codewithmosh.com/t/cant-understand-the-topic/24752/17 "2024-01-25T22:30:24Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Energy](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/energy/32/7669_2.png) [@Energy](https://forum.codewithmosh.com/u/Energy)
#### Post date: [January 25, 2024, 10:36pm UTC](https://forum.codewithmosh.com/t/cant-understand-the-topic/24752/18 "2024-01-25T22:36:38Z")

</div>

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

---

<div class="post-metadata">

### Author: ![lucidlear](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/lucidlear/32/5477_2.png) [@lucidlear](https://forum.codewithmosh.com/u/lucidlear)
#### Post date: [January 25, 2024, 11:21pm UTC](https://forum.codewithmosh.com/t/cant-understand-the-topic/24752/19 "2024-01-25T23:21:04Z")

</div>

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

```auto
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

```

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

```auto
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

---

<div class="post-metadata">

### Author: ![Energy](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/energy/32/7669_2.png) [@Energy](https://forum.codewithmosh.com/u/Energy)
#### Post date: [January 27, 2024, 3:04pm UTC](https://forum.codewithmosh.com/t/cant-understand-the-topic/24752/20 "2024-01-27T15:04:56Z")

</div>

Where exactly in the settings.py file should it be

[Next page](https://forum.codewithmosh.com/t/cant-understand-the-topic/24752.md?page=2)
