Giter VIP home page Giter VIP logo

django-app5's Introduction

Trip Tracking App

This app allows user to track their vacations with notes. The project features login page, signup page, and application dashboard that allows users to create and edit their trips with photos.

User Auth

Trip -> User is many to one relationship (models.ForeignKey)

#user auth
from django.contrib.auth import get_user_model
User = get_user_model()


# Trip model
class Trip(models.Model):
    city = models.CharField(max_length=50)
    countryCode = models.CharField(max_length=2)
    start_date = models.DateField(blank=True, null=True) #optional
    end_date = models.DateField(blank=True, null=True) #optional
    # many to one relationship
    owner = models.ForeignKey(User, on_delete = models.CASCADE, related_name = "mytrips")


    def __str__(self):
        return self.city

Enable Images to be stored in DB

pip install pillow

Update settings.py and urls.py

# urls.py
from django.contrib import admin
from django.urls import path,include
from django.conf import settings
from django.conf.urls.static import static

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('triptrack.urls')),
]

if settings.DEBUG:
    urlpatterns += static(settings.MEDIA_URL, document_root = settings.MEDIA_ROOT)



# settings.py
MEDIA_URL = '/media/'  # www.mysite.com/media/img-1
MEDIA_ROOT = os.path.join(BASE_DIR, 'media/') # path to the actual file

Built-in Django Auth to Set Up Auth URLs

we can go to env/lib/django/contrib/auth/urls.py We can see that in auth/views.py the LoginView expects template_name = "registration/login.html"

# urls.py
urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('triptrack.urls')),
    path('accounts/', include('django.contrib.auth.urls')),
]



# settings.py
'DIRS': [os.path.join(BASE_DIR,'templates')]
# so that it can find the templates/registration/login.html

# Where should the user go after login - if not next
LOGIN_REDIRECT_URL = 'trip-list'

Resource: https://developer.mozilla.org/en-US/docs/Learn/Server-side/Django/Authentication

  • accounts/ login/ [name='login']
  • accounts/ logout/ [name='logout']
  • accounts/ password_change/ [name='password_change']
  • accounts/ password_change/done/ [name='password_change_done']
  • accounts/ password_reset/ [name='password_reset']
  • accounts/ password_reset/done/ [name='password_reset_done']
  • accounts/ reset/// [name='password_reset_confirm']
  • accounts/ reset/done/ [name='password_reset_complete']

django-app5's People

Contributors

languagexange avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.