DEV Community

Cover image for Retail Website built with Django P2 (2020-02-05)
Peiwen Li
Peiwen Li

Posted on

5 3

Retail Website built with Django P2 (2020-02-05)

Django:


Animate your element


after cloned a django project:

execute the following command

$ python3 -m venv venv
$ source venv/bin/activate
(venv) $ pip install -r requirement.txt
(venv) $ pythong manage.py runserver 127.0.0.1:8080 #(or some other port)
Enter fullscreen mode Exit fullscreen mode

Django admin site

  • $ python manage.py creatsuperuser creates users with attr is_superuser or is_staff
  • class ModelAdmin from django.contrib.admin

    • if you need to make changes to the default admin interface, you need to create a object of ModelAdmin like so: class AuthorAdmin(admin.ModelAdmin):, this represent Author model on admin dashboard
    • instead of registering like this: admin.site.register(Author), you have to use a decorator to your AuthorAdmin class like so:
    from django.contrib import admin
    from .models import Author
    from myproject.admin_site import custom_admin_site
    
    # Reader and Editor objects have to have a ForeignKey field pointing at Author
    @admin.register(Author, Reader, Editor, site=custom_admin_site)
    class AuthorAdmin(admin.ModelAdmin):
        pass
    
    • Create InlineModelAdmin object to display extra info on a model in admin add page.

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay