Skip to content

Instantly share code, notes, and snippets.

@wess
Created March 19, 2015 20:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wess/c6486b19b7d0c2c1e398 to your computer and use it in GitHub Desktop.
Save wess/c6486b19b7d0c2c1e398 to your computer and use it in GitHub Desktop.
# company/models.py
from django.conf import settings
from django.db import models
from diagnose.models import IdentityModel
from users.models import User
class Company(IdentityModel):
name = models.CharField(max_length=200)
website = models.URLField()
logo = models.FileField()
owner = models.OneToOneField("users.User", related_name='company')
# disciplines/models.py
from django.db import models
from diagnose.models import BaseModel
class Discipline(BaseModel):
company = models.ForeignKey('company.Company', related_name='disciplines')
name = models.CharField(max_length=200)
description = models.CharField(max_length=200)
sort_order = models.PositiveIntegerField(default=1)
is_active = models.BooleanField(default=True)
# BaseModel
class BaseModel(models.Model):
logs = generic.GenericRelation('logs.Log')
updated_on = models.DateTimeField(auto_now=True)
created_on = models.DateTimeField(auto_now_add=True)
class Meta:
abstract = True
get_latest_by = 'updated_on'
# View Code
d = Discipline.objects.get(id=int(discipline_id), company=company)
d.delete()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment