#35896: i'm trying to make a edit option in my farmer profile   and all the 
code i
verified twice and trice but still not get it where the concret field kinda
error occur
--------------------------------+-----------------------------------------
     Reporter:  arif-hussain09  |                     Type:  Bug
       Status:  new             |                Component:  Uncategorized
      Version:  5.0             |                 Severity:  Normal
     Keywords:                  |             Triage Stage:  Unreviewed
    Has patch:  0               |      Needs documentation:  0
  Needs tests:  0               |  Patch needs improvement:  0
Easy pickings:  0               |                    UI/UX:  0
--------------------------------+-----------------------------------------
 AttributeError at /update-farmerForm/0e922a2a-6dac-4472-bb5e-6af12f5f9e2a/
 'ModelFormOptions' object has no attribute 'concrete_fields'
 Request Method: POST
 Request URL:    http://127.0.0.1:982/update-farmerForm/0e922a2a-6dac-4472
 -bb5e-6af12f5f9e2a/
 Django Version: 5.1.3
 Exception Type: AttributeError
 Exception Value:
 'ModelFormOptions' object has no attribute 'concrete_fields'
 Exception Location:
 C:\ARIF\programms\MINI_PROJECT\DBMS_project\Project_env\Lib\site-
 packages\django\forms\models.py, line 112, in model_to_dict
 Raised during:  Base.views.Update_Framer_Form
 Python Executable:
 C:\ARIF\programms\MINI_PROJECT\DBMS_project\Project_env\Scripts\python.exe
 Python Version: 3.12.4
 Python Path:
 ['C:\\ARIF\\programms\\MINI_PROJECT\\DBMS_project\\Sustainable_-Farming-
 _Resource-Management\\SRF',
  'C:\\Program Files
 (x86)\\CambridgeSoft\\ChemOffice2015\\ChemScript\\Lib',
 'C:\\Users\\HP\\AppData\\Local\\Programs\\Python\\Python312\\python312.zip',
  'C:\\Users\\HP\\AppData\\Local\\Programs\\Python\\Python312\\DLLs',
  'C:\\Users\\HP\\AppData\\Local\\Programs\\Python\\Python312\\Lib',
  'C:\\Users\\HP\\AppData\\Local\\Programs\\Python\\Python312',
  'C:\\ARIF\\programms\\MINI_PROJECT\\DBMS_project\\Project_env',
  'C:\\ARIF\\programms\\MINI_PROJECT\\DBMS_project\\Project_env\\Lib\\site-
 packages']
 Server time:    Thu, 07 Nov 2024 18:58:18 +0000






 // My model

 # Create Farmer
 class Farmer(models.Model):
     farmer_id=models.UUIDField(primary_key=True,default=uuid.uuid4,
 editable=False)
     name=models.CharField( max_length=100,null=False ,blank=False)
     contact=models.CharField(max_length=15)
     profile_picture=models.ImageField(upload_to="farmers/",blank=True
 ,null=True)

     # for traking the performance of farmer
     performance=models.DecimalField(max_digits=5, decimal_places=2)

     # Many to many relationship with farmers and farm
     farms = models.ManyToManyField('Farm', related_name='farmers',
 blank=True)

     def farm_count(self):
         return self.farms.count()

     def total_yield(self):
         return sum(crop.yield_amount  for farm in  self.farms.all() for
 crop  in farm.crops.all())

     def __str__(self):
         return f'Name: {self.name}'







 // model form
 class FarmerForm(forms.ModelForm):
     class Meta:
         model = Farmer
         fields = ['name', 'contact', 'profile_picture', 'performance',
 'farms']
         widgets = {
             'name': forms.TextInput(attrs={'class': 'form-control'}),
             'contact': forms.TextInput(attrs={'class': 'form-control'}),
             'profile_picture': forms.ClearableFileInput(attrs={'class':
 'form-control'}),
             'performance': forms.NumberInput(attrs={'class': 'form-
 control'}),
             'farms': forms.SelectMultiple(attrs={'class': 'form-
 control'}),
         }



 // model view




 def Update_Framer_Form(request,id):
     farmer=get_object_or_404(Farmer,id=farmer.farmer_id)
     form=FarmerForm(instance=farmer)
     if request.method=="POST":
         form=FarmerForm(request.POST,instance=form)
         if form.is_valid():
             form.save()
             return redirect('farmer_list')
     context={
         'form':form,
     }
     return render(request,"Base/farmForm.html",context=context)






 //html code


 {% extends "main.html" %}

 {% block content %}
 <div class="container mt-5">
     <div class="row">
         <div class="col-md-8">
             <!-- Farmer Information -->
             <h2>{{ farmer.name }}'s Profile</h2>
             <p><strong>Contact:</strong> {{ farmer.contact }}</p>
             <p><strong>Total Farms:</strong> {{ farms.count }}</p>
             <p><strong>Total Yield:</strong> {{ total_yield }} kg</p>
             <button ><a href="{%url 'update-farmerForm'
 farmer.farmer_id%}">Edit Profile</a></button>

             <!-- Farm List -->
             <h3 class="mt-4">Farms</h3>
             <table class="table table-bordered mt-3">
                 <thead class="table-light">
                     <tr>
                         <th>Farm Name</th>
                         <th>Location</th>
                         <th>Soil Type</th>
                         <th>Total Crops</th>
                     </tr>
                 </thead>
                 <tbody>
                     {% for farm in farms %}
                     <tr>
                         <td>{{ farm.name }}</td>
                         <td>{{ farm.location }}</td>
                         <td>{{ farm.soil_type }}</td>
                         <td>{{ farm.crops.count }}</td>
                     </tr>
                     {% empty %}
                     <tr>
                         <td colspan="4">No farms available.</td>
                     </tr>
                     {% endfor %}
                 </tbody>
             </table>
         </div>
         <!-- Profile Image Section -->
         <div class="col-md-4 text-center">
             <img src="{{ farmer.profile_image_url|default:'default-
 image.jpg' }}" alt="Profile Picture" class="img-fluid rounded-circle mt-3"
 style="max-width: 200px;">
             <p class="mt-3"><strong>{{ farmer.name }}</strong></p>
         </div>
     </div>
 </div>

 <!-- Edit Profile Modal -->
 <div class="modal fade" id="editProfileModal" tabindex="-1" aria-
 labelledby="editProfileModalLabel" aria-hidden="true">
     <div class="modal-dialog">
         <div class="modal-content">
             <div class="modal-header">
                 <h5 class="modal-title" id="editProfileModalLabel">Edit
 Profile</h5>
                 <button type="button" class="btn-close" data-bs-
 dismiss="modal" aria-label="Close"></button>
             </div>
             <div class="modal-body">
                 <form id="editProfileForm">
                     <div class="mb-3">
                         <label for="farmerName" class="form-
 label">Name</label>
                         <input type="text" class="form-control"
 id="farmerName" value="{{ farmer.name }}" required>
                     </div>
                     <div class="mb-3">
                         <label for="farmerContact" class="form-
 label">Contact</label>
                         <input type="tel" class="form-control"
 id="farmerContact" value="{{ farmer.contact }}" required>
                     </div>
                     <div class="mb-3">
                         <label for="profilePic" class="form-label">Profile
 Picture URL</label>
                         <input type="url" class="form-control"
 id="profilePic" value="{{ farmer.profile_image_url|default:'' }}"
 required>
                     </div>
                 </form>
             </div>
             <div class="modal-footer">
                 <button type="button" class="btn btn-secondary" data-bs-
 dismiss="modal">Close</button>
                 <button type="button" class="btn btn-primary"
 onclick="updateProfile()">Save Changes</button>
             </div>
         </div>
     </div>
 </div>

 <!-- Bootstrap JS and dependencies -->
 <script
 
src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js";></script>
 <script
 
src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js";></script>

 <!-- JavaScript for modal functionality -->
 <script>
     function updateProfile() {
         // Function to update farmer profile
         alert('Profile updated successfully!');
         $('#editProfileModal').modal('hide');
     }
 </script>
 {% endblock %}
-- 
Ticket URL: <https://code.djangoproject.com/ticket/35896>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/django-updates/0107019308058455-1ba502a2-d7f2-44b4-812b-520af7c5dddf-000000%40eu-central-1.amazonses.com.

Reply via email to