0

Below is my Participant class. I want to create a custom code that concatenates the country field with the auto-generated primary key. Whatever I've tried till now has failed, can anyone help me, please. The structure of the code is supposed to be the country first and the primary key second. I need this because when I print my report the code should be present in it

class Participant(models.Model):
    first_name = models.CharField(max_length=100)
    last_Name = models.CharField(max_length=100)
    country = CountryField()`enter code here`
    trainer = models.CharField(choices = trainer, max_length=100, )
    gender = models.CharField(choices= gender, max_length=50)

    title = models.CharField(choices= title_Choice, max_length=100, blank=True, null=True)
    date_of_birth = models.DateField(null=True, blank=True )


    contact_address = models.CharField(max_length=1000, blank=True, null=True)
    work_phone = models.CharField(max_length = 30, blank=True, null=True)
    fax_number = models.CharField(max_length = 100, blank=True, null=True)
    home_phone = models.CharField(max_length=30, blank=True, null=True)
    email = models.EmailField
    #previous_employment = models.CharField(max_length=100, blank=True, null=True)
    organization = models.ManyToManyField(Organization, blank=True)
    #role = models.ForeignKey(Role,  on_delete=models.CASCADE)

    education_level = models.CharField(choices = education_level_choice, max_length=100, blank=True, null=True)


    comments = models.CharField(max_length=1000, blank=True, null=True)

views and HTML for the data table

views.py

class Index(LoginRequiredMixin, View):
    template = 'index.html'
    login_url = '/login/'


    def get(self, request):
        session =   Session.objects.all()
        participant = Participant.objects.all() 

        num_participant = Participant.objects.all().count()


        return render(request, self.template, {'participants': participant} )

index.html

 <table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">
                                        <thead>
                                            <th>First name</th>
                                            <th>Surname</th>
                                            <th>Country</th>
                                            <th>Gender</th>
                                            <th>Organization</th>
                                            <th>Trainer</th>
                                            <th>Session</th>
                                        </tr>
                                        </thead>

                                    <tbody>
                                    {% for participant in participants %}
                                       <tr>
                                          <td>{{ participant.first_name }}</td>
                                          <td>{{ participant.last_Name }}</td>
                                          <td>{{ participant.country }}</td>
                                          <td>{{ participant.gender }}</td>
                                          <td>{{ participant.get_organization }}</td>
                                          <td>{{participant.trainer}}</td>
                                          <td>{{ participant.host_participant.all }}</td>

0 Answers0