create initial models and mobile test for mojtaba eshaghi
This commit is contained in:
@@ -45,9 +45,15 @@ INSTALLED_APPS = [
|
||||
'rest_framework_simplejwt',
|
||||
'apps.authentication.apps.AuthenticationConfig',
|
||||
'apps.authorization.apps.AuthorizationConfig',
|
||||
'apps.captcha_app.apps.CaptchaAppConfig',
|
||||
'apps.core.apps.CoreConfig',
|
||||
'apps.herd.apps.HerdAppConfig',
|
||||
'apps.livestock.apps.LivestockConfig',
|
||||
'apps.pos_machine.apps.PosMachineConfig',
|
||||
'apps.tag.apps.TagConfig',
|
||||
'apps.warehouse.apps.WarehouseConfig',
|
||||
'rest_captcha',
|
||||
'captcha',
|
||||
'apps.captcha_app.apps.CaptchaAppConfig'
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
@@ -108,7 +114,7 @@ REST_FRAMEWORK = {
|
||||
}
|
||||
|
||||
SIMPLE_JWT = {
|
||||
"ACCESS_TOKEN_LIFETIME": timedelta(minutes=5),
|
||||
"ACCESS_TOKEN_LIFETIME": timedelta(days=1),
|
||||
"REFRESH_TOKEN_LIFETIME": timedelta(days=1),
|
||||
"ROTATE_REFRESH_TOKENS": False,
|
||||
"BLACKLIST_AFTER_ROTATION": False,
|
||||
|
||||
@@ -21,4 +21,5 @@ urlpatterns = [
|
||||
path('admin/', admin.site.urls),
|
||||
path('auth/', include('apps.authentication.urls')),
|
||||
path('', include('apps.captcha_app.api.v1.urls')),
|
||||
path('', include('apps.core.urls')),
|
||||
]
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from apps.authentication.api.v1.serializers.jwt import CustomizedTokenObtainPairSerializer
|
||||
from rest_framework_simplejwt.authentication import JWTAuthentication
|
||||
from rest_framework_simplejwt.views import TokenObtainPairView
|
||||
from rest_framework.viewsets import ModelViewSet
|
||||
from rest_framework.decorators import action
|
||||
@@ -10,10 +11,12 @@ class CustomizedTokenObtainPairView(TokenObtainPairView):
|
||||
serializer_class = CustomizedTokenObtainPairSerializer
|
||||
|
||||
|
||||
# Example Code
|
||||
class Authentication(ModelViewSet):
|
||||
queryset = User
|
||||
serializer_class = ''
|
||||
permission_classes = ''
|
||||
authentication_classes = [JWTAuthentication]
|
||||
|
||||
@action(
|
||||
methods=['post', ],
|
||||
|
||||
@@ -2,6 +2,7 @@ from rest_framework_simplejwt.serializers import TokenObtainPairSerializer
|
||||
from apps.captcha_app import exceptions as captcha_exception
|
||||
from rest_framework_simplejwt.settings import api_settings
|
||||
from django.contrib.auth.models import update_last_login
|
||||
from apps.authentication.models import User
|
||||
from rest_framework import exceptions
|
||||
from django.core.cache import cache
|
||||
from typing import Any
|
||||
@@ -51,9 +52,12 @@ class CustomizedTokenObtainPairSerializer(TokenObtainPairSerializer): # noqa
|
||||
|
||||
token = super().get_token(user)
|
||||
|
||||
# get customized user
|
||||
auth_user_model = User.objects.get(username=user.username)
|
||||
|
||||
# Add custom claims
|
||||
token['name'] = user.username
|
||||
token['mobile'] = user.mobile
|
||||
token['national_code'] = user.national_code
|
||||
token['mobile'] = auth_user_model.mobile
|
||||
token['national_code'] = auth_user_model.national_code
|
||||
|
||||
return token
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
# Generated by Django 4.2.20 on 2025-05-05 07:54
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('authentication', '0004_user_otp_status'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='user',
|
||||
name='address',
|
||||
field=models.TextField(max_length=1000, null=True),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='user',
|
||||
name='birthdate',
|
||||
field=models.DateTimeField(null=True),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='user',
|
||||
name='nationality',
|
||||
field=models.CharField(max_length=20, null=True),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='user',
|
||||
name='ownership',
|
||||
field=models.IntegerField(default=1, help_text='number 1 is natural & number 2 is legal'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='user',
|
||||
name='phone',
|
||||
field=models.CharField(max_length=18, null=True),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='user',
|
||||
name='photo',
|
||||
field=models.CharField(max_length=50, null=True),
|
||||
),
|
||||
]
|
||||
17
apps/authentication/migrations/0006_remove_user_ownership.py
Normal file
17
apps/authentication/migrations/0006_remove_user_ownership.py
Normal file
@@ -0,0 +1,17 @@
|
||||
# Generated by Django 4.2.20 on 2025-05-05 08:20
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('authentication', '0005_user_address_user_birthdate_user_nationality_and_more'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='user',
|
||||
name='ownership',
|
||||
),
|
||||
]
|
||||
18
apps/authentication/migrations/0007_user_ownership.py
Normal file
18
apps/authentication/migrations/0007_user_ownership.py
Normal file
@@ -0,0 +1,18 @@
|
||||
# Generated by Django 4.2.20 on 2025-05-05 08:25
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('authentication', '0006_remove_user_ownership'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='user',
|
||||
name='ownership',
|
||||
field=models.CharField(choices=[('N', 'Natural'), ('L', 'Legal')], default='N', help_text='N is natural & L is legal', max_length=1),
|
||||
),
|
||||
]
|
||||
@@ -7,8 +7,22 @@ from apps.core.models import BaseModel
|
||||
|
||||
class User(AbstractUser, BaseModel):
|
||||
mobile = models.CharField(max_length=18)
|
||||
phone = models.CharField(max_length=18, null=True)
|
||||
national_code = models.CharField(max_length=16)
|
||||
photo = models.CharField(max_length=50)
|
||||
birthdate = models.DateTimeField(null=True)
|
||||
nationality = models.CharField(max_length=20, null=True)
|
||||
ownership_types = (
|
||||
('N', 'Natural'),
|
||||
('L', 'Legal')
|
||||
)
|
||||
ownership = models.CharField(
|
||||
max_length=1,
|
||||
choices=ownership_types,
|
||||
default='N',
|
||||
help_text="N is natural & L is legal"
|
||||
)
|
||||
address = models.TextField(max_length=1000, null=True)
|
||||
photo = models.CharField(max_length=50, null=True)
|
||||
province = models.ForeignKey(
|
||||
'Province',
|
||||
on_delete=models.CASCADE,
|
||||
|
||||
@@ -22,9 +22,7 @@ class CustomizeRestCaptchaView(views.APIView):
|
||||
key = str(uuid.uuid4())
|
||||
value = random_char_challenge(settings.CAPTCHA_LENGTH)
|
||||
cache_key = utils.get_cache_key(key)
|
||||
print(cache_key)
|
||||
cache.set(cache_key, value, settings.CAPTCHA_TIMEOUT)
|
||||
print(cache.get(cache_key))
|
||||
|
||||
# generate image
|
||||
image_bytes = generate_image(value)
|
||||
@@ -37,7 +35,3 @@ class CustomizeRestCaptchaView(views.APIView):
|
||||
'image_decode': 'base64'
|
||||
}
|
||||
return response.Response(data)
|
||||
|
||||
def get(self, request):
|
||||
key = cache.get("rest_captcha_9e3ca166-c2f8-41e8-8f19-aa6f520fc123.0")
|
||||
return response.Response(key)
|
||||
|
||||
9
apps/core/api.py
Normal file
9
apps/core/api.py
Normal file
@@ -0,0 +1,9 @@
|
||||
from rest_framework import viewsets
|
||||
from apps.core.models import MobileTest
|
||||
from rest_framework.response import Response
|
||||
from apps.core.serializers import MobileTestSerializer
|
||||
|
||||
|
||||
class MobileTestViewSet(viewsets.ModelViewSet):
|
||||
queryset = MobileTest.objects.all()
|
||||
serializer_class = MobileTestSerializer
|
||||
35
apps/core/migrations/0001_initial.py
Normal file
35
apps/core/migrations/0001_initial.py
Normal file
@@ -0,0 +1,35 @@
|
||||
# Generated by Django 4.2.20 on 2025-05-05 11:41
|
||||
|
||||
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),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='MobileTest',
|
||||
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)),
|
||||
('latitude', models.DecimalField(decimal_places=16, max_digits=22)),
|
||||
('longitude', models.DecimalField(decimal_places=16, max_digits=22)),
|
||||
('count', models.IntegerField(default=0)),
|
||||
('time', models.DateTimeField(auto_now_add=True)),
|
||||
('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,
|
||||
},
|
||||
),
|
||||
]
|
||||
@@ -23,3 +23,10 @@ class BaseModel(models.Model):
|
||||
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
||||
|
||||
class MobileTest(BaseModel):
|
||||
latitude = models.DecimalField(max_digits=22, decimal_places=16)
|
||||
longitude = models.DecimalField(max_digits=22, decimal_places=16)
|
||||
count = models.IntegerField(default=0)
|
||||
time = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
8
apps/core/serializers.py
Normal file
8
apps/core/serializers.py
Normal file
@@ -0,0 +1,8 @@
|
||||
from apps.core.models import MobileTest
|
||||
from rest_framework import serializers
|
||||
|
||||
|
||||
class MobileTestSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = MobileTest
|
||||
fields = '__all__'
|
||||
@@ -1,3 +1,11 @@
|
||||
from rest_framework.routers import DefaultRouter
|
||||
from apps.core.api import MobileTestViewSet
|
||||
from django.urls import path, include
|
||||
|
||||
router = DefaultRouter()
|
||||
router.register('mobile_test', MobileTestViewSet, basename='mobile_test')
|
||||
app_name = "core"
|
||||
|
||||
urlpatterns = []
|
||||
urlpatterns = [
|
||||
path('core/', include(router.urls))
|
||||
]
|
||||
|
||||
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'
|
||||
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
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
@@ -1,3 +0,0 @@
|
||||
from django.db import models
|
||||
|
||||
# Create your models here.
|
||||
@@ -1,3 +0,0 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
@@ -1,3 +0,0 @@
|
||||
from django.shortcuts import render
|
||||
|
||||
# Create your views here.
|
||||
0
apps/pos_machine/__init__.py
Normal file
0
apps/pos_machine/__init__.py
Normal file
3
apps/pos_machine/admin.py
Normal file
3
apps/pos_machine/admin.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
||||
6
apps/pos_machine/apps.py
Normal file
6
apps/pos_machine/apps.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class PosMachineConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'apps.pos_machine'
|
||||
0
apps/pos_machine/management/__init__.py
Normal file
0
apps/pos_machine/management/__init__.py
Normal file
0
apps/pos_machine/management/commands/__init__.py
Normal file
0
apps/pos_machine/management/commands/__init__.py
Normal file
1
apps/pos_machine/management/commands/command.py
Normal file
1
apps/pos_machine/management/commands/command.py
Normal file
@@ -0,0 +1 @@
|
||||
# Your custom management commands go here.
|
||||
0
apps/pos_machine/migrations/__init__.py
Normal file
0
apps/pos_machine/migrations/__init__.py
Normal file
0
apps/pos_machine/mobile/api/__init__.py
Normal file
0
apps/pos_machine/mobile/api/__init__.py
Normal file
0
apps/pos_machine/mobile/api/v1/__init__.py
Normal file
0
apps/pos_machine/mobile/api/v1/__init__.py
Normal file
0
apps/pos_machine/mobile/api/v1/serializers.py
Normal file
0
apps/pos_machine/mobile/api/v1/serializers.py
Normal file
0
apps/pos_machine/mobile/api/v1/urls.py
Normal file
0
apps/pos_machine/mobile/api/v1/urls.py
Normal file
0
apps/pos_machine/mobile/api/v1/views.py
Normal file
0
apps/pos_machine/mobile/api/v1/views.py
Normal file
0
apps/pos_machine/models.py
Normal file
0
apps/pos_machine/models.py
Normal file
25
apps/pos_machine/permissions.py
Normal file
25
apps/pos_machine/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/pos_machine/pos/api/__init__.py
Normal file
0
apps/pos_machine/pos/api/__init__.py
Normal file
0
apps/pos_machine/pos/api/v1/__init__.py
Normal file
0
apps/pos_machine/pos/api/v1/__init__.py
Normal file
0
apps/pos_machine/pos/api/v1/serializers.py
Normal file
0
apps/pos_machine/pos/api/v1/serializers.py
Normal file
0
apps/pos_machine/pos/api/v1/urls.py
Normal file
0
apps/pos_machine/pos/api/v1/urls.py
Normal file
0
apps/pos_machine/pos/api/v1/views.py
Normal file
0
apps/pos_machine/pos/api/v1/views.py
Normal file
0
apps/pos_machine/pos/tests/test_common_services.py
Normal file
0
apps/pos_machine/pos/tests/test_common_services.py
Normal file
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user