Re: How to create groups for users in Django

2016-03-04 Thread Luis Zárate
Años observation

Person.objects.create(name=request.user)

Lazy object is set but name is charfield.
M1is not saved.
form.save() create other group that is not used.



El jueves, 3 de marzo de 2016,  escribió:
> Hello!
>
> I have a problem, like in topic, with creating groups in django. I was
searching everywhere and nothing was so interested.
>
> What i want from this section: I would like to by filling a column with
the name of the group, formed a quite new group, on the occasion of adding
me as one of the members and preferably, as a leader, who can add other
users to the group.
>
> My problem: I did one form for name, and when i sending a request, i got
nothing, only the stie is re-loaded. I have some code but don;t know what
to do next..
>
> My code:
>
> models.py:
>
> class Person(models.Model):
>
> name = models.CharField(max_length=128)
>
> def __str__(self): # __unicode__ on Python 2
> return self.name
>
>
> class Group(models.Model):
> name = models.CharField(max_length=128)
> leader = models.CharField(max_length=50)
> members = models.ManyToManyField(Person, through='Membership')
>
> def __str__(self): # __unicode__ on Python 2
> return self.name
>
>
> class Membership(models.Model):
> person = models.ForeignKey(Person)
> group = models.ForeignKey(Group)
> date_joined = models.DateField()
> invite_reason = models.CharField(max_length=64)
>
> forms.py:
>
> class GroupForm(forms.ModelForm):
>
> class Meta:
> model = Group
> fields = ('name',)
>
> views.py:
>
> @login_required
> def groups(request):
>
> if request.method == "POST":
> form = GroupForm(request.POST)
> if form.is_valid():
>
> grupa = Group.objects.create(name="grupa")
> per = Person.objects.create(name=request.user)
> m1 = Membership(person=per, group=grupa, date_joined=(1999, 8, 8),
invite_reason="Needed programmer.")
> form.save()
>
>
> return render(request, 'groups.html', {'form':form})
>
> else:
> form = GroupForm()
>
> return render(request, 'groups.html', {'form': form})
>
> groups.html:
>
> {% block profile %}
>
> 
> 
> Create your new group !
> 
> {% csrf_token %}
> {{ form|crispy }}
> Go!
> 
> 
>
> {% endblock %}
>
> This is it... Can anyone could help me with that? I spend few days with
it and 0 progress.
>
> Thanks for any help!
>
> Damian
>
> --
> 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/b71b3e7e-a168-4f1c-aaf7-655bdee86212%40googlegroups.com
.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
"La utopía sirve para caminar" Fernando Birri

-- 
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/CAG%2B5VyOH7A28WLKTQSjLzH8Ug1YSfG3hbjth%3DnNJB-L5WoY4HA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


How to create groups for users in Django

2016-03-03 Thread dszczesniak


Hello! 

I have a problem, like in topic, with creating groups in django. I was 
searching everywhere and nothing was so interested.

What i want from this section: I would like to by filling a column with the 
name of the group, formed a quite new group, on the occasion of adding me 
as one of the members and preferably, as a leader, who can add other users 
to the group.

My problem: I did one form for name, and when i sending a request, i got 
nothing, only the stie is re-loaded. I have some code but don;t know what 
to do next..


My code:


models.py:


class Person(models.Model):

name = models.CharField(max_length=128)
def __str__(self):  # __unicode__ on Python 2
return self.name

class Group(models.Model):
name = models.CharField(max_length=128)
leader = models.CharField(max_length=50)
members = models.ManyToManyField(Person, through='Membership')

def __str__(self):  # __unicode__ on Python 2
return self.name

class Membership(models.Model):
person = models.ForeignKey(Person)
group = models.ForeignKey(Group)
date_joined = models.DateField()
invite_reason = models.CharField(max_length=64)



forms.py:



class GroupForm(forms.ModelForm):
class Meta:
model = Group
fields = ('name',)



views.py:


@login_requireddef groups(request):
if request.method == "POST":
form = GroupForm(request.POST)
if form.is_valid():

grupa = Group.objects.create(name="grupa")
per = Person.objects.create(name=request.user)
m1 = Membership(person=per, group=grupa, date_joined=(1999, 8, 8), 
invite_reason="Needed programmer.")
form.save()


return render(request, 'groups.html', {'form':form})
else:
form = GroupForm()
return render(request, 'groups.html', {'form': form})



groups.html:


{% block profile %}

 
  
Create your new group !

{% csrf_token %}
{{ form|crispy }}
Go!

  
{% endblock %}



This is it... Can anyone could help me with that? I spend few days with it 
and 0 progress.


Thanks for any help!

Damian

-- 
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/b71b3e7e-a168-4f1c-aaf7-655bdee86212%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.