Commit 31396b1c authored by Aljaž Srebrnič's avatar Aljaž Srebrnič

Add constraints

parent 9923ac69
# -*- coding: utf-8 -*-
# Generated by Django 1.11.1 on 2017-09-02 08:35
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('things', '0006_auto_20170529_1707'),
]
operations = [
migrations.AlterField(
model_name='category',
name='parent',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='things.Category', verbose_name='the parent category'),
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.11.1 on 2017-09-02 08:59
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('things', '0007_auto_20170902_1035'),
]
operations = [
migrations.AlterField(
model_name='category',
name='parent',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='things.Category', verbose_name='the parent category'),
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.11.1 on 2017-09-02 09:19
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('things', '0008_auto_20170902_1059'),
]
operations = [
migrations.AlterField(
model_name='state',
name='id',
field=models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'),
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.11.1 on 2017-09-02 15:14
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('things', '0009_auto_20170902_1119'),
]
operations = [
migrations.AlterField(
model_name='thing',
name='expiry_date',
field=models.DateField(blank=True, null=True),
),
migrations.AlterField(
model_name='thing',
name='location',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='locations.Location'),
),
migrations.AlterField(
model_name='thing',
name='parent',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='things.Thing', verbose_name='contained inside of'),
),
migrations.AlterField(
model_name='thing',
name='quantity',
field=models.FloatField(blank=True, null=True),
),
]
......@@ -16,11 +16,10 @@ class Category(models.Model):
name = models.CharField(max_length=80, null=False, unique=True)
description = models.TextField()
parent = models.ForeignKey('self', verbose_name='the parent category')
parent = models.ForeignKey('self', verbose_name='the parent category', blank=True, null=True)
class State(models.Model):
id = models.IntegerField(primary_key=True)
name = models.CharField(max_length=80)
description = models.TextField()
......@@ -35,22 +34,23 @@ class Thing(models.Model):
description = models.TextField()
categories = models.ManyToManyField(Category)
quantity = models.FloatField(null=True)
quantity = models.FloatField(null=True, blank=True)
consumable = models.BooleanField(default=False)
borrowable = models.BooleanField(default=False)
private = models.BooleanField(default=False)
location = models.ForeignKey(Location, null=True)
location = models.ForeignKey(Location, null=True, blank=True)
parent = models.ForeignKey('self',
verbose_name='contained inside of',
on_delete=models.SET_NULL,
null=True)
null=True,
blank=True)
owner = models.ForeignKey(User, verbose_name='owner of the thing')
state = models.ForeignKey(State)
metadata = JSONField()
expiry_date = models.DateField()
expiry_date = models.DateField(null=True, blank=True)
def clean(self):
if self.location and self.parent:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment