create initial models and mobile test for mojtaba eshaghi
This commit is contained in:
0
apps/herd/__init__.py
Normal file
0
apps/herd/__init__.py
Normal file
3
apps/herd/admin.py
Normal file
3
apps/herd/admin.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
||||
6
apps/herd/apps.py
Normal file
6
apps/herd/apps.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class HerdAppConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'apps.herd'
|
||||
0
apps/herd/management/__init__.py
Normal file
0
apps/herd/management/__init__.py
Normal file
0
apps/herd/management/commands/__init__.py
Normal file
0
apps/herd/management/commands/__init__.py
Normal file
1
apps/herd/management/commands/command.py
Normal file
1
apps/herd/management/commands/command.py
Normal file
@@ -0,0 +1 @@
|
||||
# Your custom management commands go here.
|
||||
46
apps/herd/migrations/0001_initial.py
Normal file
46
apps/herd/migrations/0001_initial.py
Normal file
@@ -0,0 +1,46 @@
|
||||
# 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),
|
||||
('authentication', '0007_user_ownership'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Herd',
|
||||
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)),
|
||||
('name', models.CharField(max_length=50)),
|
||||
('photo', models.CharField(max_length=50, null=True)),
|
||||
('code', models.CharField(max_length=20)),
|
||||
('postal', models.CharField(help_text='herd postal code', max_length=10, null=True)),
|
||||
('institution', models.CharField(help_text='herd institution code', max_length=20, null=True)),
|
||||
('epidemiologic', models.CharField(max_length=18, null=True)),
|
||||
('latitude', models.DecimalField(decimal_places=16, max_digits=22, null=True)),
|
||||
('longitude', models.DecimalField(decimal_places=16, max_digits=22, null=True)),
|
||||
('unit_unique_id', models.CharField(max_length=20, null=True)),
|
||||
('activity', models.CharField(choices=[('I', 'Industrial'), ('V', 'Village'), ('N', 'Nomadic')], max_length=1, null=True)),
|
||||
('activity_state', models.BooleanField(default=False)),
|
||||
('operating_license_state', models.BooleanField(default=False)),
|
||||
('capacity', models.IntegerField(default=0)),
|
||||
('contractor', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='herd_contractor', to='authentication.organization')),
|
||||
('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)),
|
||||
('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,
|
||||
},
|
||||
),
|
||||
]
|
||||
0
apps/herd/migrations/__init__.py
Normal file
0
apps/herd/migrations/__init__.py
Normal file
0
apps/herd/mobile/api/__init__.py
Normal file
0
apps/herd/mobile/api/__init__.py
Normal file
0
apps/herd/mobile/api/v1/__init__.py
Normal file
0
apps/herd/mobile/api/v1/__init__.py
Normal file
0
apps/herd/mobile/api/v1/serializers.py
Normal file
0
apps/herd/mobile/api/v1/serializers.py
Normal file
0
apps/herd/mobile/api/v1/urls.py
Normal file
0
apps/herd/mobile/api/v1/urls.py
Normal file
0
apps/herd/mobile/api/v1/views.py
Normal file
0
apps/herd/mobile/api/v1/views.py
Normal file
0
apps/herd/mobile/tests/test_common_services.py
Normal file
0
apps/herd/mobile/tests/test_common_services.py
Normal file
46
apps/herd/models.py
Normal file
46
apps/herd/models.py
Normal file
@@ -0,0 +1,46 @@
|
||||
from apps.core.models import BaseModel
|
||||
from apps.authentication import models as auth_models
|
||||
from django.db import models
|
||||
|
||||
|
||||
class Herd(BaseModel):
|
||||
name = models.CharField(max_length=50)
|
||||
photo = models.CharField(max_length=50, null=True)
|
||||
code = models.CharField(max_length=20)
|
||||
postal = models.CharField(
|
||||
max_length=10,
|
||||
help_text="herd postal code", null=True
|
||||
)
|
||||
institution = models.CharField(
|
||||
max_length=20,
|
||||
help_text="herd institution code", null=True
|
||||
)
|
||||
epidemiologic = models.CharField(max_length=18, null=True) # noqa
|
||||
contractor = models.ForeignKey(
|
||||
auth_models.Organization,
|
||||
on_delete=models.CASCADE,
|
||||
related_name="herd_contractor",
|
||||
null=True
|
||||
)
|
||||
latitude = models.DecimalField(max_digits=22, decimal_places=16, null=True)
|
||||
longitude = models.DecimalField(max_digits=22, decimal_places=16, null=True)
|
||||
unit_unique_id = models.CharField(max_length=20, null=True)
|
||||
activity_types = (
|
||||
("I", "Industrial"),
|
||||
("V", "Village"),
|
||||
("N", "Nomadic")
|
||||
)
|
||||
activity = models.CharField(
|
||||
choices=activity_types,
|
||||
max_length=1,
|
||||
null=True
|
||||
)
|
||||
activity_state = models.BooleanField(default=False)
|
||||
operating_license_state = models.BooleanField(default=False)
|
||||
capacity = models.IntegerField(default=0)
|
||||
|
||||
def __str__(self):
|
||||
return f'{self.name}-{self.code}'
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
super(Herd, self).save(*args, **kwargs)
|
||||
25
apps/herd/permissions.py
Normal file
25
apps/herd/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/herd/pos/api/__init__.py
Normal file
0
apps/herd/pos/api/__init__.py
Normal file
0
apps/herd/pos/api/v1/__init__.py
Normal file
0
apps/herd/pos/api/v1/__init__.py
Normal file
0
apps/herd/pos/api/v1/serializers.py
Normal file
0
apps/herd/pos/api/v1/serializers.py
Normal file
0
apps/herd/pos/api/v1/urls.py
Normal file
0
apps/herd/pos/api/v1/urls.py
Normal file
0
apps/herd/pos/api/v1/views.py
Normal file
0
apps/herd/pos/api/v1/views.py
Normal file
0
apps/herd/pos/tests/test_common_services.py
Normal file
0
apps/herd/pos/tests/test_common_services.py
Normal file
1
apps/herd/services.py
Normal file
1
apps/herd/services.py
Normal file
@@ -0,0 +1 @@
|
||||
# Your services go here
|
||||
1
apps/herd/urls.py
Normal file
1
apps/herd/urls.py
Normal file
@@ -0,0 +1 @@
|
||||
# Your urls go here
|
||||
0
apps/herd/web/api/__init__.py
Normal file
0
apps/herd/web/api/__init__.py
Normal file
0
apps/herd/web/api/v1/__init__.py
Normal file
0
apps/herd/web/api/v1/__init__.py
Normal file
0
apps/herd/web/api/v1/serializers.py
Normal file
0
apps/herd/web/api/v1/serializers.py
Normal file
0
apps/herd/web/api/v1/urls.py
Normal file
0
apps/herd/web/api/v1/urls.py
Normal file
0
apps/herd/web/api/v1/views.py
Normal file
0
apps/herd/web/api/v1/views.py
Normal file
0
apps/herd/web/tests/test_common_services.py
Normal file
0
apps/herd/web/tests/test_common_services.py
Normal file
Reference in New Issue
Block a user