Skip to content

Instantly share code, notes, and snippets.

View aballah-chamakh's full-sized avatar

abdallah-chamakh aballah-chamakh

View GitHub Profile
x = np.array([[0,0],
[0,1],
[1,0],
[1,1],])
y = np.array([[1],
[0],
[0],
[1]])
np.random.seed(1)
w1 = np.random.normal(scale=0.1,size=(nb_inp,nb_h1))
w2 = np.random.normal(scale=0.1,size=(nb_h1,nb_h2))
w3 = np.random.normal(scale=0.1,size=(nb_h2,nb_out))
b1 = np.zeros(nb_h1)
b2 = np.zeros(nb_h2)
b3 = np.zeros(nb_out)
import numpy as np
learning_rate = 0.01
nb_inp = 2
nb_h1 = 150
nb_h2 = 150
nb_out = 1
from django.db.models.signals import post_save
from django.dispatch import receiver
@receiver(post_save, sender=Article)
def set_analytic_to_article(sender, instance, created, **kwargs):
if created :
analytic_obj = Analytic.objects.create(views=0)
instance.analytic = analytic_obj
instance.save()
from django.db import models
class Article(models.Model):
analytic = models.OneToOneField(on_delete=models.SET_NULL,null=Yrue)
title = models.CharField(max_length=255)
description = models.TextField()
def __str__(self):
return self.title
from django.contrib import admin
from .models import Door
admin.site.register(Door)
INSTALLED_APPS = [
... ,
'Door',
]
from django.conf.urls import include
from django.urls import path
from rest_framework import routers
from .views import DoorViewSet
router = routers.DefaultRouter()
router.register('door', DoorViewSet)
urlpatterns = [
from django.shortcuts import render
from rest_framework import viewsets,status
from rest_framework.response import Response
from rest_framework.decorators import action
from .serializers import DoorSerializer
from .models import Door
from .permissions import IsOwnerAndAuthenticated
class DoorViewSet(viewsets.ModelViewSet):
serializer_class = DoorSerializer
from rest_framework import serializers
from .models import Door
class DoorSerializer(serializers.ModelSerializer):
class Meta :
model = Door
fields = ['id','name','opened']