DEV Community

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

Posted on

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.

Top comments (0)