Skip to content
This repository has been archived by the owner on Dec 13, 2022. It is now read-only.

Commit

Permalink
django country admin customization
Browse files Browse the repository at this point in the history
- [x] tender admin view add columns contract id, contract title, country, contract date
- [x] hide: buyer, suppplier, temp data
- [x] last_contract_date added in country api
  • Loading branch information
sonikabaniya committed Apr 20, 2021
1 parent 1109ec0 commit 73604fe
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
11 changes: 4 additions & 7 deletions country/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from content.models import CountryPartner, DataImport

from .models import (
Buyer,
Country,
DataProvider,
EquityCategory,
Expand All @@ -16,8 +15,6 @@
ImportBatch,
Language,
RedFlag,
Supplier,
TempDataImportTable,
Tender,
Topic,
)
Expand All @@ -35,8 +32,8 @@ class EquityAdmin(admin.ModelAdmin):

admin.site.register(Language)
admin.site.register(Topic)
admin.site.register(Buyer)
admin.site.register(Supplier)
# admin.site.register(Buyer)
# admin.site.register(Supplier)
admin.site.register(EquityCategory, EquityAdmin)


Expand Down Expand Up @@ -165,7 +162,7 @@ class DataProviderAdmin(admin.ModelAdmin):
list_display = ("name", "country", "website")


@admin.register(TempDataImportTable)
# @admin.register(TempDataImportTable)
class TempDataImportTableAdmin(admin.ModelAdmin):
list_editable = (
"contract_date",
Expand Down Expand Up @@ -274,7 +271,7 @@ class Meta:
class TenderAdmin(admin.ModelAdmin):
readonly_fields = ("contract_value_usd",)
form = TenderForm
list_display = ("id", "contract_id", "contract_title")
list_display = ("contract_id", "contract_title", "country", "contract_date", "contract_value_usd")
search_fields = ("id", "contract_id", "contract_title")
inlines = [
GoodsAndServicesInline,
Expand Down
13 changes: 12 additions & 1 deletion country/serializers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.db.models import Count, Sum
from django.db.models import Count, Max, Sum
from rest_framework import serializers
from rest_framework_serializer_extensions.serializers import SerializerExtensionsMixin

Expand Down Expand Up @@ -28,6 +28,7 @@ class CountrySerializer(serializers.HyperlinkedModelSerializer, SerializerExtens
amount_usd = serializers.SerializerMethodField()
amount_local = serializers.SerializerMethodField()
tender_count = serializers.SerializerMethodField()
last_contract_date = serializers.SerializerMethodField()

class Meta:
model = Country
Expand Down Expand Up @@ -76,6 +77,16 @@ def get_tender_count(self, obj):
except Exception:
return obj.tenders.all().aggregate(tender_count=Count("id"))["tender_count"]

def get_last_contract_date(self, obj):
try:
if obj.last_contract_date:
return obj.last_contract_date
else:
return None

except Exception:
return obj.tenders.all().aggregate(contract_last_date=Max("contract_date"))["contract_last_date"]


class LanguageSerializer(serializers.ModelSerializer, SerializerExtensionsMixin):
class Meta:
Expand Down

0 comments on commit 73604fe

Please sign in to comment.