In first page(form), i want to search for vendor. Afterwords when i click
on one we go into another page. On this page we have performance form where
we need to give ratings from 1 to 5 for that particular vendor.
So when I rate all the fields and press save, i want to store all rating
data in sql together with vendor name, timestamp and username who saved tha
data.

That was all working fine in for loop(except vendor part, needed to enter
data in input field myself), but when i divide performance form into
separate fields in HTML all crashed. Please see txt enclosed.
Thank you for your response.


sri, 13. velj 2019. u 11:48 Mohammad Etemaddar <mohammad.etemad...@gmail.com>
napisao je:

> Dear Ivan,
> If I get you right, You have a page with form, and you want to post it to
> another page. so, fill the "action" part of html form with the second
> page's url.
>
> Also the timezone.now is allways available in any python file you are
> working on it, and also request and request.user
>
> What do you want to do exactly?
>
> On Wednesday, February 13, 2019 at 1:45:46 PM UTC+3:30, Ivan Martić wrote:
>>
>> Hi all,
>>
>> where can i find more info regarding passing values in views/forms/url.
>> What I need is to pass value from form in previous url page to the form
>> in next url page(also prefilling with data like timezone.now, request,user)
>>
>> Thank you in advance.
>> Ivan
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/5eb3df26-ae0d-44c7-8f4b-e7b0b6e5e01e%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/5eb3df26-ae0d-44c7-8f4b-e7b0b6e5e01e%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAFab_C_HtQsH7%3Dq0%3D4vYtRHN%3D5RKO0qhNow%3Degosk0RLfbdUSQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
from __future__ import unicode_literals
from django.db import models, connection
from django.utils import timezone
from datetime import date
from django.forms import widgets


GRADE_CHOICES = (
    ('1', 'Excellent'),
    ('2', 'Very good'),
    ('3', 'Good'),
    ('4', 'Adequate'),
    ('5', 'Poor')
)


class Performance(models.Model):
    id = models.AutoField(db_column='ID', primary_key=True, blank=False, 
unique=True)
    supplier_name = models.CharField(db_column='Supplier name',max_length=9, 
blank=True, null=True)
    deliverability = models.CharField(db_column='Deliverability', max_length=1, 
blank=True, null=True, choices=GRADE_CHOICES)
    goodwill = models.CharField(db_column='Goodwill', blank=True, max_length=1, 
null=True, choices=GRADE_CHOICES)
    certification = models.CharField(db_column='Certification', max_length=1, 
blank=True, null=True, choices=GRADE_CHOICES)

    compliance_with_spec_field = models.CharField(db_column='Compliance with 
spec#', max_length=1, blank=True, null=True, choices=GRADE_CHOICES)
    quality_of_the_delivery = models.CharField(db_column='Quality of the 
Delivery', max_length=1, blank=True, null=True, choices=GRADE_CHOICES)
    quantity_reliability = models.CharField(db_column='Quantity reliability', 
max_length=1, blank=True, null=True, choices=GRADE_CHOICES)
    fulfilment_of_deadlines = models.CharField(db_column='Fulfilment of 
deadlines', max_length=1, blank=True, null=True, choices=GRADE_CHOICES)

    reaction_time = models.CharField(db_column='Reaction time', max_length=1, 
blank=True, null=True, choices=GRADE_CHOICES)
    flexibilty = models.CharField(db_column='Flexibilty', max_length=1, 
blank=True, null=True, choices=GRADE_CHOICES)
    economical_offer = models.CharField(db_column='Economical offer', 
max_length=1, blank=True, null=True, choices=GRADE_CHOICES)
    price_performance_ratio = models.CharField(db_column='Price-performance 
ratio', max_length=1, blank=True, null=True, choices=GRADE_CHOICES)

    credit = models.CharField(db_column='Credit', max_length=1, blank=True, 
null=True, choices=GRADE_CHOICES)
    rating = models.CharField(db_column='Rating', max_length=255, blank=True, 
null=True, choices=GRADE_CHOICES)
    rated_by = models.CharField(db_column='Rated by', max_length=255, 
blank=True, null=True)
    date_of_entry = models.DateTimeField(db_column='Date of entry', 
default=timezone.now)


    class Meta:
        managed = False
        db_table = 'Performance'

    def __str__(self):
        return '%s %s %s %s %s %s %s %s %s %s %s %s %s %s' % 
(self.supplier_name, self.deliverability, self.goodwill, self.certification, 
                self.compliance_with_spec_field, self.quality_of_the_delivery, 
self.quantity_reliability, self.fulfilment_of_deadlines,
                        self.reaction_time, self.flexibilty, 
self.economical_offer, self.price_performance_ratio,
                        self.credit, self.rating
                )

class Vendors(models.Model):
    id = models.AutoField(db_column='ID', primary_key=True, blank=False, 
unique=True, null=False)
    lifnr = models.CharField(db_column='LIFNR', max_length=50, blank=True, 
null=True)
    name1 = models.CharField(db_column='NAME1', max_length=150, blank=True, 
null=True)
    land1 = models.CharField(db_column='LAND1', max_length=50, blank=True, 
null=True)
    groupid = models.IntegerField(db_column='GROUPID')

    class Meta:
        managed = False
        db_table = 'Vendors'

    def __str__(self):
        return '%s %s %s %s' % (self.lifnr, self.name1, self.land1, 
self.groupid)
from django import forms
from .models import Performance
from django.forms import widgets
from django.utils import timezone

GRADE_CHOICES = (
    ('1', 'Excellent'),
    ('2', 'Very good'),
    ('3', 'Good'),
    ('4', 'Adequate'),
    ('5', 'Poor')
)

class PerformanceForm(forms.ModelForm):
        deliverability = forms.ChoiceField(choices=GRADE_CHOICES, 
widget=forms.RadioSelect())
        goodwill = forms.ChoiceField(choices=GRADE_CHOICES, 
widget=forms.RadioSelect())
        certification = forms.ChoiceField(choices=GRADE_CHOICES, 
widget=forms.RadioSelect())
        compliance_with_spec_field = forms.ChoiceField(choices=GRADE_CHOICES, 
widget=forms.RadioSelect())

        quality_of_the_delivery = forms.ChoiceField(choices=GRADE_CHOICES, 
widget=forms.RadioSelect())
        quantity_reliability = forms.ChoiceField(choices=GRADE_CHOICES, 
widget=forms.RadioSelect())
        fulfilment_of_deadlines = forms.ChoiceField(choices=GRADE_CHOICES, 
widget=forms.RadioSelect())
        reaction_time = forms.ChoiceField(choices=GRADE_CHOICES, 
widget=forms.RadioSelect())

        flexibilty = forms.ChoiceField(choices=GRADE_CHOICES, 
widget=forms.RadioSelect())
        economical_offer = forms.ChoiceField(choices=GRADE_CHOICES, 
widget=forms.RadioSelect())
        price_performance_ratio = forms.ChoiceField(choices=GRADE_CHOICES, 
widget=forms.RadioSelect())
        credit = forms.ChoiceField(choices=GRADE_CHOICES, 
widget=forms.RadioSelect())

        class Meta:
                model = Performance
                fields = [
                        'supplier_name', 
                        'deliverability', 
                        'goodwill', 
                        'certification', 
                        'compliance_with_spec_field', 
                        'quality_of_the_delivery', 
                        'quantity_reliability', 
                        'fulfilment_of_deadlines', 
                        'reaction_time', 
                        'flexibilty', 
                        'economical_offer', 
                        'price_performance_ratio', 
                        'credit' 
                ]

        def __init__(self, *args, **kwargs):
                super(PerformanceForm, self).__init__(*args, **kwargs)

        def save(self, rated_by):
                performance = super(PerformanceForm, self).save(commit=False)
                performance.rated_by = rated_by
                performance.date_of_entry = timezone.now()
                performance.rating = 0
                #performance.supplier_name = supplier_name

                performance.save(commit=True)

                return performance

from django.shortcuts import render, redirect
from django.http import HttpResponse
from .models import Performance, Vendors
from django.db import connection
from .forms import PerformanceForm
from django.core.mail import send_mail
from django.conf import settings
from django.core.mail import send_mail
from django.contrib import messages
from django.contrib.auth import login, logout
from django.contrib.auth.decorators import user_passes_test, login_required
from django.db.models import Q
from django.shortcuts import get_object_or_404


def performance_view(request):
        lista_vendora = Vendors.objects.all()
        trazi = None
        search = request.GET.get("search", None)

        if search:
                trazi =  Vendors.objects.filter(Q(lifnr__icontains=search) | 
Q(name1__icontains=search))

        context = {"lista_vendora" : lista_vendora, 'trazi':trazi, 
'search':search}
        return render(request, 'performance.html', context)


def performance_entry_view(request, url_id):
        vendor = Vendors.objects.all().get(id=url_id)
        vendor.lifnr

        form = PerformanceForm(request.POST or None, instance=vendor )
        context = {'lista':vendor, 'form':form}

        if form.is_valid():
                performance = form.save(rated_by=request.user)
        return render(request, 'performance-entry.html', context)


Reply via email to