create initial models and mobile test for mojtaba eshaghi
This commit is contained in:
0
apps/livestock/__init__.py
Normal file
0
apps/livestock/__init__.py
Normal file
3
apps/livestock/admin.py
Normal file
3
apps/livestock/admin.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
||||
6
apps/livestock/apps.py
Normal file
6
apps/livestock/apps.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class LivestockConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'apps.livestock'
|
||||
0
apps/livestock/management/__init__.py
Normal file
0
apps/livestock/management/__init__.py
Normal file
0
apps/livestock/management/commands/__init__.py
Normal file
0
apps/livestock/management/commands/__init__.py
Normal file
1
apps/livestock/management/commands/command.py
Normal file
1
apps/livestock/management/commands/command.py
Normal file
@@ -0,0 +1 @@
|
||||
# Your custom management commands go here.
|
||||
37
apps/livestock/migrations/0001_initial.py
Normal file
37
apps/livestock/migrations/0001_initial.py
Normal file
@@ -0,0 +1,37 @@
|
||||
# Generated by Django 4.2.20 on 2025-05-05 11:54
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
('herd', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='LiveStock',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('create_date', models.DateTimeField(auto_now_add=True)),
|
||||
('modify_date', models.DateTimeField(auto_now=True)),
|
||||
('trash', models.BooleanField(default=False)),
|
||||
('type', models.CharField(choices=[('L', 'Light'), ('H', 'Heavy')], max_length=1)),
|
||||
('species', models.CharField(choices=[], max_length=1)),
|
||||
('birthdate', models.DateTimeField(null=True)),
|
||||
('gender', models.IntegerField(choices=[(1, 'male'), (2, 'female')], default=1)),
|
||||
('created_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='%(class)s_createdby', to=settings.AUTH_USER_MODEL)),
|
||||
('herd', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='live_stock_herd', to='herd.herd')),
|
||||
('modified_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='%(class)s_modifiedby', to=settings.AUTH_USER_MODEL)),
|
||||
],
|
||||
options={
|
||||
'abstract': False,
|
||||
},
|
||||
),
|
||||
]
|
||||
22
apps/livestock/migrations/0002_initial.py
Normal file
22
apps/livestock/migrations/0002_initial.py
Normal file
@@ -0,0 +1,22 @@
|
||||
# Generated by Django 4.2.20 on 2025-05-05 11:54
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
('livestock', '0001_initial'),
|
||||
('tag', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='livestock',
|
||||
name='tag',
|
||||
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='livestock_tag', to='tag.tag'),
|
||||
),
|
||||
]
|
||||
0
apps/livestock/migrations/__init__.py
Normal file
0
apps/livestock/migrations/__init__.py
Normal file
0
apps/livestock/mobile/api/__init__.py
Normal file
0
apps/livestock/mobile/api/__init__.py
Normal file
0
apps/livestock/mobile/api/v1/__init__.py
Normal file
0
apps/livestock/mobile/api/v1/__init__.py
Normal file
0
apps/livestock/mobile/api/v1/serializers.py
Normal file
0
apps/livestock/mobile/api/v1/serializers.py
Normal file
0
apps/livestock/mobile/api/v1/urls.py
Normal file
0
apps/livestock/mobile/api/v1/urls.py
Normal file
0
apps/livestock/mobile/api/v1/views.py
Normal file
0
apps/livestock/mobile/api/v1/views.py
Normal file
0
apps/livestock/mobile/tests/test_common_services.py
Normal file
0
apps/livestock/mobile/tests/test_common_services.py
Normal file
40
apps/livestock/models.py
Normal file
40
apps/livestock/models.py
Normal file
@@ -0,0 +1,40 @@
|
||||
from apps.core.models import BaseModel
|
||||
from apps.herd import models as herd_models
|
||||
from apps.tag import models as tag_models
|
||||
from django.db import models
|
||||
|
||||
|
||||
class LiveStock(BaseModel):
|
||||
herd = models.ForeignKey(
|
||||
herd_models.Herd,
|
||||
on_delete=models.CASCADE,
|
||||
related_name="live_stock_herd",
|
||||
null=True
|
||||
)
|
||||
tag = models.ForeignKey(
|
||||
tag_models.Tag,
|
||||
on_delete=models.CASCADE,
|
||||
related_name='livestock_tag',
|
||||
null=True
|
||||
)
|
||||
types = (
|
||||
('L', 'Light'),
|
||||
('H', 'Heavy')
|
||||
)
|
||||
type = models.CharField(max_length=1, choices=types)
|
||||
species_type = (
|
||||
()
|
||||
)
|
||||
species = models.CharField(max_length=1, choices=species_type)
|
||||
birthdate = models.DateTimeField(null=True)
|
||||
gender_type = (
|
||||
(1, 'male'),
|
||||
(2, 'female')
|
||||
)
|
||||
gender = models.IntegerField(choices=gender_type, default=1)
|
||||
|
||||
def __str__(self):
|
||||
return f'{self.get_species_display()}-{self.get_type_display()}'
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
super(LiveStock, self).save(*args, **kwargs)
|
||||
25
apps/livestock/permissions.py
Normal file
25
apps/livestock/permissions.py
Normal file
@@ -0,0 +1,25 @@
|
||||
from rest_framework import permissions
|
||||
|
||||
|
||||
# example Code
|
||||
class AuthorAllStaffAllButEditOrReadOnly(permissions.BasePermission):
|
||||
edit_methods = ("PUT", "PATCH")
|
||||
|
||||
def has_permission(self, request, view):
|
||||
if request.user.is_authenticated:
|
||||
return True
|
||||
|
||||
def has_object_permission(self, request, view, obj):
|
||||
if request.user.is_superuser:
|
||||
return True
|
||||
|
||||
if request.method in permissions.SAFE_METHODS:
|
||||
return True
|
||||
|
||||
if obj.author == request.user:
|
||||
return True
|
||||
|
||||
if request.user.is_staff and request.method not in self.edit_methods:
|
||||
return True
|
||||
|
||||
return False
|
||||
0
apps/livestock/pos/api/__init__.py
Normal file
0
apps/livestock/pos/api/__init__.py
Normal file
0
apps/livestock/pos/api/v1/__init__.py
Normal file
0
apps/livestock/pos/api/v1/__init__.py
Normal file
0
apps/livestock/pos/api/v1/serializers.py
Normal file
0
apps/livestock/pos/api/v1/serializers.py
Normal file
0
apps/livestock/pos/api/v1/urls.py
Normal file
0
apps/livestock/pos/api/v1/urls.py
Normal file
0
apps/livestock/pos/api/v1/views.py
Normal file
0
apps/livestock/pos/api/v1/views.py
Normal file
0
apps/livestock/pos/tests/test_common_services.py
Normal file
0
apps/livestock/pos/tests/test_common_services.py
Normal file
1
apps/livestock/services.py
Normal file
1
apps/livestock/services.py
Normal file
@@ -0,0 +1 @@
|
||||
# Your services go here
|
||||
1
apps/livestock/urls.py
Normal file
1
apps/livestock/urls.py
Normal file
@@ -0,0 +1 @@
|
||||
# Your urls go here
|
||||
0
apps/livestock/web/api/__init__.py
Normal file
0
apps/livestock/web/api/__init__.py
Normal file
0
apps/livestock/web/api/v1/__init__.py
Normal file
0
apps/livestock/web/api/v1/__init__.py
Normal file
0
apps/livestock/web/api/v1/serializers.py
Normal file
0
apps/livestock/web/api/v1/serializers.py
Normal file
0
apps/livestock/web/api/v1/urls.py
Normal file
0
apps/livestock/web/api/v1/urls.py
Normal file
0
apps/livestock/web/api/v1/views.py
Normal file
0
apps/livestock/web/api/v1/views.py
Normal file
0
apps/livestock/web/tests/test_common_services.py
Normal file
0
apps/livestock/web/tests/test_common_services.py
Normal file
Reference in New Issue
Block a user