Re: Can anybody answe how i can access infromation from the parent modell i my HTML template in Django?

2020-06-30 Thread The Sha
Thank you friend, it worked

Den tisdag 30 juni 2020 kl. 13:22:11 UTC+2 skrev Andréas Kühne:
>
> All you need to do is update the render call a dictionary with the 
> customuser variable in it:
>
> return render(request, 'members/member_contact_form.html', 
> {'ContactFormset':ContactFormset, 'Address Formset':AddressFormset, 
> 'customuser': 
> customuser })
>
> Regards,
>
> Andréas
>
>
> Den tis 30 juni 2020 kl 11:06 skrev The Sha  >:
>
>> Ok i understand, how du i put the CustomUser in the render method so i 
>> cant get {{ CustomUser.first_name }} in this case?
>>
>> Den tisdag 30 juni 2020 kl. 11:00:53 UTC+2 skrev Andréas Kühne:
>>>
>>> Hi,
>>>
>>> You need to pass the variables that you want to use in the template to 
>>> the template itself. You do this here:
>>>
>>> return render(request, 'members/member_contact_form.html', 
>>> {'ContactFormset':ContactFormset, 'AddressFormset':AddressFormset })
>>>
>>> The dictionary you add to the render method there contains all the 
>>> objects that you can get in the template itself. So if you want to add 
>>> something called object you need to add that to the dictionary.
>>>
>>> Med vänliga hälsningar,
>>>
>>> Andréas
>>>
>>> Den tis 30 juni 2020 kl 10:38 skrev The Sha :
>>>
>>>>
>>>>
>>>>
>>>>
>>>> <https://stackoverflow.com/posts/62653247/timeline>
>>>>
>>>> I have a two formsets rendered in a view called ContactIndex, the 
>>>> parent model for this view is the CustomUser model. I want to present the 
>>>> first_name of the user object in my html template. I've tried these tags 
>>>> without success any advise?
>>>>
>>>> This is the tags in my HTML template:
>>>>
>>>> {{ customuser.first_name }} - does not work
>>>>
>>>> {{ object.first_name }} - does not work
>>>>
>>>>
>>>> *This is my view:*
>>>>
>>>> def ContactIndex(request, CustomUser_id):
>>>> customuser = CustomUser.objects.get(pk=CustomUser_id)
>>>> if request.method == "POST":
>>>> ContactFormset = ContactInlineFormSet(request.POST, 
>>>> request.FILES, instance=customuser)
>>>> AddressFormset = AddressInlineFormSet(request.POST, 
>>>> request.FILES, instance=customuser)
>>>> if ContactFormset.is_valid() or AddressFormset.is_valid():
>>>> AddressFormset.save()
>>>> ContactFormset.save()
>>>> # Do something. Should generally end with a redirect. For 
>>>> example:
>>>> return redirect ('ContactIndex', 
>>>> CustomUser_id=customuser.id)
>>>> else:
>>>> ContactFormset = ContactInlineFormSet(instance=customuser)
>>>> AddressFormset = AddressInlineFormSet(instance=customuser)
>>>> return render(request, 'members/member_contact_form.html', 
>>>> {'ContactFormset':ContactFormset, 'Address
>>>>
>>>> Formset':AddressFormset })
>>>>
>>>> -- 
>>>> 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...@googlegroups.com.
>>>> To view this discussion on the web visit 
>>>> https://groups.google.com/d/msgid/django-users/865ff205-9a1d-4f62-bbe4-d2d12da22374o%40googlegroups.com
>>>>  
>>>> <https://groups.google.com/d/msgid/django-users/865ff205-9a1d-4f62-bbe4-d2d12da22374o%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>> .
>>>>
>>> -- 
>> 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...@googlegroups.com .
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/2ab18788-3a31-4c7f-bba7-890580540153o%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/2ab18788-3a31-4c7f-bba7-890580540153o%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>

-- 
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/036bac0e-f999-401e-afd6-7a14f940bf5fo%40googlegroups.com.


Re: Can anybody answe how i can access infromation from the parent modell i my HTML template in Django?

2020-06-30 Thread The Sha
It worked thank you my friend!

Den tisdag 30 juni 2020 kl. 11:00:53 UTC+2 skrev Andréas Kühne:
>
> Hi,
>
> You need to pass the variables that you want to use in the template to the 
> template itself. You do this here:
>
> return render(request, 'members/member_contact_form.html', 
> {'ContactFormset':ContactFormset, 'AddressFormset':AddressFormset })
>
> The dictionary you add to the render method there contains all the objects 
> that you can get in the template itself. So if you want to add something 
> called object you need to add that to the dictionary.
>
> Med vänliga hälsningar,
>
> Andréas
>
> Den tis 30 juni 2020 kl 10:38 skrev The Sha  >:
>
>>
>>
>>
>>
>> <https://stackoverflow.com/posts/62653247/timeline>
>>
>> I have a two formsets rendered in a view called ContactIndex, the parent 
>> model for this view is the CustomUser model. I want to present the 
>> first_name of the user object in my html template. I've tried these tags 
>> without success any advise?
>>
>> This is the tags in my HTML template:
>>
>> {{ customuser.first_name }} - does not work
>>
>> {{ object.first_name }} - does not work
>>
>>
>> *This is my view:*
>>
>> def ContactIndex(request, CustomUser_id):
>> customuser = CustomUser.objects.get(pk=CustomUser_id)
>> if request.method == "POST":
>> ContactFormset = ContactInlineFormSet(request.POST, 
>> request.FILES, instance=customuser)
>> AddressFormset = AddressInlineFormSet(request.POST, 
>> request.FILES, instance=customuser)
>> if ContactFormset.is_valid() or AddressFormset.is_valid():
>> AddressFormset.save()
>> ContactFormset.save()
>> # Do something. Should generally end with a redirect. For 
>> example:
>> return redirect ('ContactIndex', CustomUser_id=customuser.id)
>> else:
>> ContactFormset = ContactInlineFormSet(instance=customuser)
>> AddressFormset = AddressInlineFormSet(instance=customuser)
>> return render(request, 'members/member_contact_form.html', 
>> {'ContactFormset':ContactFormset, 'Address
>>
>> Formset':AddressFormset })
>>
>> -- 
>> 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...@googlegroups.com .
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/865ff205-9a1d-4f62-bbe4-d2d12da22374o%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/865ff205-9a1d-4f62-bbe4-d2d12da22374o%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>

-- 
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/0e80aec7-2a58-41d8-8125-425db2231313o%40googlegroups.com.


Re: Can anybody answe how i can access infromation from the parent modell i my HTML template in Django?

2020-06-30 Thread The Sha
Ok i understand, how du i put the CustomUser in the render method so i cant 
get {{ CustomUser.first_name }} in this case?

Den tisdag 30 juni 2020 kl. 11:00:53 UTC+2 skrev Andréas Kühne:
>
> Hi,
>
> You need to pass the variables that you want to use in the template to the 
> template itself. You do this here:
>
> return render(request, 'members/member_contact_form.html', 
> {'ContactFormset':ContactFormset, 'AddressFormset':AddressFormset })
>
> The dictionary you add to the render method there contains all the objects 
> that you can get in the template itself. So if you want to add something 
> called object you need to add that to the dictionary.
>
> Med vänliga hälsningar,
>
> Andréas
>
> Den tis 30 juni 2020 kl 10:38 skrev The Sha  >:
>
>>
>>
>>
>>
>> <https://stackoverflow.com/posts/62653247/timeline>
>>
>> I have a two formsets rendered in a view called ContactIndex, the parent 
>> model for this view is the CustomUser model. I want to present the 
>> first_name of the user object in my html template. I've tried these tags 
>> without success any advise?
>>
>> This is the tags in my HTML template:
>>
>> {{ customuser.first_name }} - does not work
>>
>> {{ object.first_name }} - does not work
>>
>>
>> *This is my view:*
>>
>> def ContactIndex(request, CustomUser_id):
>> customuser = CustomUser.objects.get(pk=CustomUser_id)
>> if request.method == "POST":
>> ContactFormset = ContactInlineFormSet(request.POST, 
>> request.FILES, instance=customuser)
>> AddressFormset = AddressInlineFormSet(request.POST, 
>> request.FILES, instance=customuser)
>> if ContactFormset.is_valid() or AddressFormset.is_valid():
>> AddressFormset.save()
>> ContactFormset.save()
>> # Do something. Should generally end with a redirect. For 
>> example:
>> return redirect ('ContactIndex', CustomUser_id=customuser.id)
>> else:
>> ContactFormset = ContactInlineFormSet(instance=customuser)
>> AddressFormset = AddressInlineFormSet(instance=customuser)
>> return render(request, 'members/member_contact_form.html', 
>> {'ContactFormset':ContactFormset, 'Address
>>
>> Formset':AddressFormset })
>>
>> -- 
>> 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...@googlegroups.com .
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/865ff205-9a1d-4f62-bbe4-d2d12da22374o%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/865ff205-9a1d-4f62-bbe4-d2d12da22374o%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>

-- 
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/2ab18788-3a31-4c7f-bba7-890580540153o%40googlegroups.com.


Re: Two models one form, or use generic CreateView

2020-06-09 Thread The Sha
Ok intressant, i cant find any good exemplen. Thank you for the reply. Im new 
to django can you maybe be more specific with som examples or point me in the 
right direktion? 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/c484bbef-d743-48c4-b13f-1a1e5f122976o%40googlegroups.com.


Re: Custom template tags - instance.templatetag

2020-06-09 Thread The Sha


Den tisdag 2 juni 2020 kl. 22:53:06 UTC+2 skrev Jan Gregorczyk:
>
> Hi! How to change my template tag?
> from django import template
>
> register = template.Library()
>
> @register.simple_tag
> def votes_up_exists(answer, user_id):
> pass
>
> how I use it - {% votes_up_exists answer request.user.id %}
> how I would like to use it - {% answer.votes_up_exists user_id %}
>
>

-- 
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/7f9a51cf-4762-4b16-99ec-6ced288ade5fo%40googlegroups.com.


Two models one form, or use generic CreateView

2020-06-09 Thread The Sha
Hi 

I hava a problem in django, i have to models one is a CustomUser Model and 
the other is a Address model. 

The problem is that when i create a generic CreateView for the Address 
model and use a pk: url the address form wont get the instance of the users 
PK for adding a new address.

my models look like this, Even though i pass the PK in the URL the 
CreateView does not understand that i want to add a address to user with 
id: 42 in this example. How can i solve this problem?







The URL
 path('/address', views.AddressCreateView.as_view(), name
='Address-add'),


*This is my view*
class AddressCreateView(CreateView):
model = Address
template_name = 'members/address_form.html'
success_url = reverse_lazy('MemberIndex')
fields = ('CustomUser', 'address', 'zip_code', 'city', 'state','active')


*The model*
class CustomUser(AbstractBaseUser, PermissionsMixin):
email = models.EmailField(_('email address'), unique=True)
personal_Id = models.CharField(max_length=12, blank=False)
first_name = models.CharField(_('first name'), max_length=30, blank=True
)
middle_name = models.CharField('middle name', max_length=30, blank=True)
last_name = models.CharField(_('last name'), max_length=30, blank=True)
is_staff = models.BooleanField(default=False)
is_active = models.BooleanField(default=True)
date_joined = models.DateTimeField(default=timezone.now)
avatar = models.ImageField(upload_to='images', blank=True)

def __str__(self):
return self.email

def full_name(self):
return '%s %s %s' % (self.first_name, self.middle_name, self
.last_name)

USERNAME_FIELD = 'email'
REQUIRED_FIELDS = []


objects = CustomUserManager()

class Address(models.Model):
CustomUser = models.ForeignKey(CustomUser, on_delete=models.CASCADE)
address = models.CharField(max_length=60, blank=False)
zip_code = models.CharField(max_length=8, blank=False)
city = models.CharField(max_length=30, blank=False)
state = models.CharField(max_length=30, blank=False)
active = models.BooleanField(name='active', default=True, editable=True)
address_reg_date = models.DateTimeField(default=timezone.now)
class Meta:
verbose_name_plural = "Address"
 
def __str__(self):
 return self.address +', '+ str(self.zip_code) + ', ' + self.city





-- 
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/d0d3596f-6c0e-4928-8e57-7eb5476821d3o%40googlegroups.com.