A tribal Administration has various villages
Each village is led by a chief
A resident is allocated a property and becomes an account holder
An account holder may have dependents and these can be a spouse, a child who may also be a student
Register each resident and create a models with the following fuelds: name, surname, id number, address, email, mobile number, gender, employment status, date of birth.
Residents may request a proof of residence and print it out as a PDF
Create a Django System that can perform the above
Implement the system complete with models, views, urls, forms, templates
Include an authentication functionality where only authenticated residents can access their own information.
Do not include id numbers in the proof of residence, only name, surname, address
Also create a model for staff
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
from django.http import HttpResponse
from django.template.loader import render_to_string
from weasyprint import HTML
def proof_of_residence(request, pk):
resident = get_object_or_404(Resident, pk=pk)
html = render_to_string('residents/proof_of_residence.html', {'resident': resident})
response = HttpResponse(content_type='application/pdf')
response['Content-Disposition'] = f'filename="proof_of_residence_{resident.name}_{resident.surname}.pdf"'
HTML(string=html).write_pdf(response)
return response
Forms
Resident form:
python
from django import forms
from .models import Resident
class ResidentForm(forms.ModelForm):
class Meta:
model = Resident
fields = ['name', 'surname', 'id_number', 'address', 'email', 'mobile_number', 'gender', 'employment_status', 'date_of_birth']
To ensure that only authenticated residents can access their own information, you can use Django's built-in authentication system and add a login_required decorator to the resident detail view:
python
from django.contrib.auth.decorators import login_required
@login_required
def resident_detail(request, pk):
# ...
This is just a high-level overview of how you can structure your Django system. You'll need to fill in the details and customize it to fit your specific needs.