Skip to content

Instantly share code, notes, and snippets.

View aballah-chamakh's full-sized avatar

abdallah-chamakh aballah-chamakh

View GitHub Profile
from .models import Lecture,PlayList
class InLineLecture(admin.TabularInline):
model = Lecture
class PlayListAdmin(admin.ModelAdmin):
inlines = [InLineLecture]
list_display = ('title','slug')
admin.site.register(Lecture)
from django.db import models
class PlayList(models.Model):
title = models.CharField(max_length=255)
slug = models.SlugField()
description = models.TextField()
def __str__(self):
return self.title
from django.contrib import admin
from .models import Lecture
class LectureAdmin(admin.ModelAdmin):
list_display = ('title','slug','video_url','description_length')
list_display_link = ('slug')
iist_diplay_editable = ('title','video_url')
list_display_filter = ('title')
list_display_search = ('title','description')
from django.db import models
class Lecture(models.Model):
title = models.CharField(max_length=255)
slug = models.SlugField()
description = models.TextField()
video_url = models.CharField(max_length=500)
def __str__(self):
import random
import string
from django.utils.text import slugify
def random_string_generator(size=5, chars=string.ascii_lowercase + string.digits):
return ''.join(random.choice(chars) for _ in range(size))
def unique_slug_generator(instance, new_slug=None):
# add the account app and all the dependency
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
from django.contrib import admin
from django.urls import path,include
from rest_framework_jwt.views import obtain_jwt_token,refresh_jwt_token
# from Door import urls as DoorUrls
urlpatterns = [
path('admin/', admin.site.urls),
path('api/',include('account.urls')),
]
from django.conf.urls import include
from django.urls import path
from rest_framework import routers
from .views import UserViewSet,ProfileViewSet
router = routers.DefaultRouter()
router.register('user', UserViewSet)
router.register('profile', ProfileViewSet)
from rest_framework import permissions
class IsOwnerAndAuthenticated(permissions.BasePermission):
def has_permission(self, request, view):
# let permmission just for create user
if request.method == 'POST' :
return True
from django.shortcuts import render
from rest_framework.decorators import action
from rest_framework.response import Response
from rest_framework import viewsets,status,generics
from .models import User,Profile
from .serializers import SimpleProfileSerializer,ProfileSerializer
from .UserSerializer import UserSerializer
from .permissions import IsOwnerAndAuthenticated