import mrkazi livesock excel tablr

This commit is contained in:
2026-02-09 14:45:45 +03:30
parent f13851a30d
commit c02c165ff9
4 changed files with 51 additions and 2 deletions

View File

@@ -1,8 +1,9 @@
import pandas as pd
from django.core.management.base import BaseCommand
from django.utils.dateparse import parse_datetime
from apps.livestock.models import LiveStock, LiveStockType, LiveStockSpecies
from apps.herd.models import Herd
from apps.livestock.models import LiveStock, LiveStockType, LiveStockSpecies
from apps.tag.models import Tag
@@ -16,6 +17,7 @@ class Command(BaseCommand):
path = options['excel_path']
df = pd.read_excel(path)
records = df.to_dict(orient='records')
print(records[1])
self.stdout.write(self.style.SUCCESS(f"{len(records)} records loaded."))
@@ -46,7 +48,7 @@ class Command(BaseCommand):
herd_cache[herd_code] = herd
tag_code = r.get('national_id_livestock_code')
tag = Tag.objects.filter(code=tag_code).first()
tag = Tag.objects.filter(tag_code=tag_code).first()
if not tag:
skipped += 1
continue

View File

@@ -0,0 +1,38 @@
# Generated by Django 5.0 on 2026-02-09 10:58
import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('livestock', '0018_livestockspecies_en_name_alter_livestockspecies_name'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
operations = [
migrations.CreateModel(
name='ExcelLiveStocks',
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)),
('creator_info', models.CharField(max_length=100, null=True)),
('modifier_info', models.CharField(max_length=100, null=True)),
('trash', models.BooleanField(default=False)),
('national_id', models.CharField(max_length=250, null=True)),
('herd_code', models.CharField(max_length=150, null=True)),
('species', models.CharField(max_length=250, null=True)),
('birthdate', models.CharField(max_length=150, null=True)),
('gender', models.CharField(max_length=150, null=True)),
('agent_code', models.CharField(max_length=150, null=True)),
('created_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='%(class)s_createddby', 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,
},
),
]

View File

@@ -103,6 +103,15 @@ class LiveStock(BaseModel):
return super(LiveStock, self).save(*args, **kwargs)
class ExcelLiveStocks(BaseModel):
national_id = models.CharField(max_length=250, null=True)
herd_code = models.CharField(max_length=150, null=True)
species = models.CharField(max_length=250, null=True)
birthdate = models.CharField(max_length=150, null=True)
gender = models.CharField(max_length=150, null=True)
agent_code = models.CharField(max_length=150, null=True)
class TemporaryLiveStock(BaseModel):
rancher = models.ForeignKey(
herd_models.Rancher,