import mrkazi livesock excel tablr
This commit is contained in:
@@ -1,8 +1,9 @@
|
|||||||
import pandas as pd
|
import pandas as pd
|
||||||
from django.core.management.base import BaseCommand
|
from django.core.management.base import BaseCommand
|
||||||
from django.utils.dateparse import parse_datetime
|
from django.utils.dateparse import parse_datetime
|
||||||
from apps.livestock.models import LiveStock, LiveStockType, LiveStockSpecies
|
|
||||||
from apps.herd.models import Herd
|
from apps.herd.models import Herd
|
||||||
|
from apps.livestock.models import LiveStock, LiveStockType, LiveStockSpecies
|
||||||
from apps.tag.models import Tag
|
from apps.tag.models import Tag
|
||||||
|
|
||||||
|
|
||||||
@@ -16,6 +17,7 @@ class Command(BaseCommand):
|
|||||||
path = options['excel_path']
|
path = options['excel_path']
|
||||||
df = pd.read_excel(path)
|
df = pd.read_excel(path)
|
||||||
records = df.to_dict(orient='records')
|
records = df.to_dict(orient='records')
|
||||||
|
print(records[1])
|
||||||
|
|
||||||
self.stdout.write(self.style.SUCCESS(f"{len(records)} records loaded."))
|
self.stdout.write(self.style.SUCCESS(f"{len(records)} records loaded."))
|
||||||
|
|
||||||
@@ -46,7 +48,7 @@ class Command(BaseCommand):
|
|||||||
herd_cache[herd_code] = herd
|
herd_cache[herd_code] = herd
|
||||||
|
|
||||||
tag_code = r.get('national_id_livestock_code')
|
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:
|
if not tag:
|
||||||
skipped += 1
|
skipped += 1
|
||||||
continue
|
continue
|
||||||
|
|||||||
38
apps/livestock/migrations/0019_excellivestocks.py
Normal file
38
apps/livestock/migrations/0019_excellivestocks.py
Normal 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,
|
||||||
|
},
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -103,6 +103,15 @@ class LiveStock(BaseModel):
|
|||||||
return super(LiveStock, self).save(*args, **kwargs)
|
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):
|
class TemporaryLiveStock(BaseModel):
|
||||||
rancher = models.ForeignKey(
|
rancher = models.ForeignKey(
|
||||||
herd_models.Rancher,
|
herd_models.Rancher,
|
||||||
|
|||||||
Reference in New Issue
Block a user