Many to Many relationships in template

2020-02-27 Thread Robb Rodirguez Jr.
Good day guys, im new to django im having in many to many relationship 
display in template

How can display this into a normal list..

from . 
, , , , 
]>

to.
webadmin
kim
sem
quinito
user1

Here's my code

model.py 

class ListOfUser(models.Model):
users = models.ManyToManyField(User, verbose_name='List of User')



views.py

def listofusers(request):
userlist = ListOfUser.objects.get(id=1)

form = ListofUserForms()

context = {
'form': form,
'userlist': userlist
}
return render(request, 'listofusers.html', context)


template

{{userlist.users.all}}


-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/f3e604a7-5613-4f12-8aa6-526b19ae0fc7%40googlegroups.com.


need help on multiple file uploads

2020-03-12 Thread Robb Rodirguez Jr.
im having to with multiple file uploads, when i tried to upload files only 
1 file will be saved..

here's my code:
views.py

def attachments(request):
to = TravelOrder.objects.order_by('-date_filling').last()
if request.method == 'POST':
form = AttachmentsForm(request.POST, request.FILES)
if form.is_valid():
for f in request.FILES.getlist('attachment'):
instance = form.save(commit=False)
instance.travel_order = to
instance.attachment = f
instance.save()
print('YEW')
return redirect('attach')

else:
form = AttachmentsForm()

context = {
'form': form
}
return render(request, 'employee/attachments.html', context)

models.py

class TravelOrder(models.Model):
created_by = models.CharField(max_length=255)
start_date = models.DateField(auto_now=False)
end_date = models.DateField(auto_now=False)
wfp = models.CharField(max_length=255, verbose_name='Wfp Where to be 
charged')
purpose_of_travel = models.CharField(max_length=255)
region = models.ForeignKey(Region, on_delete=models.CASCADE)
venue = models.CharField(max_length=255)
date_filling = models.DateTimeField(auto_now_add=True)
status = models.CharField(max_length=15)

def __str__(self):
return self.purpose_of_travel


class Attachements(models.Model):
at_id = models.AutoField(primary_key=True)
travel_order = models.ForeignKey(TravelOrder, on_delete=models.CASCADE)
attachment = models.FileField(upload_to='attachment/')


forms.py

class AttachmentsForm(forms.ModelForm):
class Meta:
model = Attachements
exclude = ['travel_order']
fields = ('attachment',)
widgets = {
'attachment': forms.ClearableFileInput(attrs={'multiple':True})
}



hope you can help me guys. thank you..

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/6d59b634-b6d9-4597-b502-012de4ac3c89%40googlegroups.com.


null value in column “ProjectName_id” violates not-null constraint

2019-09-11 Thread Robb Rodirguez Jr.
Hello need help on null value in column "ProjectName_id" violates not-null 
constraint, im new to django
i want my ProjectName_id (Foreignkey) is the same/equal id that user choose 
in my majordetails = ProjectNameInviToBid.objects.get(id=sid) please help 
me...

my model views

class ProjectNameInviToBid(models.Model):
ProjectName = models.CharField(max_length=255, verbose_name='Project Name', 
null=True)
DateCreated = models.DateField(auto_now=True)

class InviToBid(models.Model):
today = date.today()
ProjectName = models.ForeignKey('ProjectNameInviToBid', 
on_delete=models.CASCADE)
NameOfFile = models.CharField(max_length=255, verbose_name='Name of File')

my views.py

def project_name_details(request, sid):

majordetails = ProjectNameInviToBid.objects.get(id=sid)

if request.method == 'POST':
form = invitoBidForm(request.POST, request.FILES)
if form.is_valid():
*majordetails = InviToBid.ProjectName*
form.save()
messages.success(request, 'File has been Uploaded')
else:
form = invitoBidForm()

args = {
'majordetails': majordetails,
'form': form

}
return render(request,'content/invitoBid/bacadmininvitoBid.html', args)

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/f25acfab-8fc3-4597-9905-376d9d27f0b9%40googlegroups.com.