Re: [PROBLEM] Creacion de primera apps de djangogirls, error en models.py

2020-04-19 Thread Gavin Wiener
¿Has instalado Django con pip?

On Saturday, April 18, 2020 at 5:35:22 AM UTC+8, lucas bonet wrote:
>
> Hola, estoy creando la primera aplicacion de django con pyton y cuando 
> llega el momento de configurar en el directorio de blog--> model.py copio 
> las lineas de comando del tutrorial y me reporta errores. los erorres me 
> los marca en From, como que no tiene una carpeta otra de acceso llamada 
> django.conf y asi con los otros dos archivos. A donde tendria que cambiar 
> esa configuracion para poder continuar?
>  Muchas gracias y espero poder sumarme a la comunidad para ir creciendo. 
> Saludos!
> from django.conf import settings
> from django.db import models
> from django.utils import timezone
>
>
>

-- 
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/af187256-78fb-46c2-9e22-4a71c1fcb30c%40googlegroups.com.


Re: Models as choices

2020-04-16 Thread Gavin Wiener
If you're serializing as JSON, that primary key is literally just integer 
then, and the foreign key relationship requires an instance of that foreign 
key. So you'll need to fetch an instance of the object first.

I've had this issue before, that's how I resolved it.

On Friday, April 17, 2020 at 1:51:05 PM UTC+8, shreehari Vaasistha L wrote:
>
> i get this error when trying in your way:
>
> Cannot assign "2": "User.highest_degree" must be a "Degree" instance.
>
> On Thursday, April 16, 2020 at 5:31:07 PM UTC+5:30, Gavin Wiener wrote:
>>
>> Couldn't the User just have a ForeignKey on countries?
>>
>> On Thursday, April 16, 2020 at 12:52:07 PM UTC+8, shreehari Vaasistha L 
>> wrote:
>>>
>>> how can i use model x values as choices for model y ?
>>>
>>> for eg:
>>> class countries(models.Model):
>>>  country = models.CharField(max_length=200)
>>>
>>>  def __str__(self):
>>>  return self.country 
>>>
>>> class User(AbstractUser):
>>>  """User model."""
>>>
>>>  username = None
>>>  full_name = models.CharField(_("Full Name"), max_length=50, default="Full 
>>> Name") 
>>>  country_choices = models.CharField(choices=countries
>>>
>>

-- 
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/c563335e-cd3f-4204-9aec-6c098dc3a525%40googlegroups.com.


Re: Cannot Redirect to other page

2020-04-16 Thread Gavin Wiener
I did include example, the last sentence of the first paragraph.

You need to get rid of the inner function, I don't know why that was 
written. I needs to look more

if request.method =="GET":
   return the regular page
elif request.method == "POST":
   process the answers that have been sent by the user

Basically follow this, 
https://docs.djangoproject.com/en/3.0/topics/forms/#get-and-post

You'll need to make changes to;

1. Your template
2. Removing the inner function
3. Processing the form correctly
4. Handling the GET and POST differently


On Wednesday, April 15, 2020 at 8:22:35 PM UTC+8, pui hei Li wrote:
>
> I am writing a view that retrieve an answer from game2.html, then check 
> the answer; if the answer is correct, the view will redirect user to 
> correct.html, if the answer is incorrect, then user will be redirected to 
> incorrect.html. 
>
> The problem now is after clicking the submit button, user won't be 
> redirected. And after clicking the submit button, the url changed from 
> localhost:8000/game2 to 
> http://localhost:8000/game2/?ans2=4&game2Answer=Submit 
>
> It seems the view is not verifying the answer, and it is also redirecting 
> user to anywhere.
>
> How do I solve it?
>
> *morse_logs/views.py*
>
> @login_required()
> def game2(request):
> """The Game2 page"""
> if request.user and not request.user.is_anonymous:
> user = request.user
>
> def verifyGame2(val1):
> user_score, created = userScore.objects.get_or_create(user=user)
>
> if val1 == 4:
> # user's score declared in model increase 5points
> # display correct and 5 points added to user
> user_score.score += 5
> user_score.save()
> return redirect(reverse('morse_logs:incorrect'))
> else:
> # user's score declared in model has no point
> # display incorrect and 0 point added to user
> return redirect(reverse('morse_logs:incorrect'))
>
>
> ans2 = request.GET.get('ans2', '')
> if ans2 == '':
> ans2 = 0
>
> verifyGame2(int(ans2))
>
> return render(request, 'morse_logs/game2.html')
>
>
> *morse_logs/game2.html*
>
> {% extends "morse_logs/base.html" %}
>
> {% block content %}
> GAME 2
> 
> GAME 2
> 2 + 2 = ?
> 
> 
> 
> 
> 
> {% endblock content %}
>
>
> *morse_logs/correct.html*
>
> {% extends "morse_logs/base.html" %}
>
> {% block content %}
> Correct!
> 
> Congratulations! Your answer is CORRECT!
> 
> {% endblock content %}
>
>
> *morse_logs/incorrect.html*
>
> {% extends "morse_logs/base.html" %}
>
> {% block content %}
> Inorrect...
> 
> Unfortunately! Your answer is Incorrect!
> 
> {% endblock content %}
>
>
> *morse_logs/urls.py*
>
> from django.urls import path, include
> from morse_logs import views
>
> app_name = 'morse_logs'
>
> urlpatterns = [
> #The path() function is passed four arguments, two required: route and 
> view, and two optional: kwargs, and name.
> # Home Page
> path(r'', views.index, name='index'),
> # Page that shows all topics
> path(r'topics/', views.topics, name='topics'),
> path(r'cipher/', views.cipher, name='cipher'),
> path(r'decipher/', views.decipher, name='decipher'),
> path(r'tutorialIndex/', views.tutorialIndex, name='tutorialIndex'),
> path(r'gameDirectory/', views.gameDirectory, name='gameDirectory'),
> path(r'correct/', views.correct, name='correct'),
> path(r'incorrect/', views.incorrect, name='incorrect'),
> path(r'game1/', views.game1, name='game1'),
> path(r'game2/', views.game2, name='game2'),
>
> ]
>
>

-- 
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/f4db16e3-e914-4eea-af8d-4ff04ec1abd8%40googlegroups.com.


Re: Cannot Redirect to other page

2020-04-16 Thread Gavin Wiener
I did include some examples, the last sentence of the first paragraph.

You need to get rid of the inner function, I don't know why it was created. 
It needs to look more like this

if request.method == "GET":



On Wednesday, April 15, 2020 at 8:22:35 PM UTC+8, pui hei Li wrote:
>
> I am writing a view that retrieve an answer from game2.html, then check 
> the answer; if the answer is correct, the view will redirect user to 
> correct.html, if the answer is incorrect, then user will be redirected to 
> incorrect.html. 
>
> The problem now is after clicking the submit button, user won't be 
> redirected. And after clicking the submit button, the url changed from 
> localhost:8000/game2 to 
> http://localhost:8000/game2/?ans2=4&game2Answer=Submit 
>
> It seems the view is not verifying the answer, and it is also redirecting 
> user to anywhere.
>
> How do I solve it?
>
> *morse_logs/views.py*
>
> @login_required()
> def game2(request):
> """The Game2 page"""
> if request.user and not request.user.is_anonymous:
> user = request.user
>
> def verifyGame2(val1):
> user_score, created = userScore.objects.get_or_create(user=user)
>
> if val1 == 4:
> # user's score declared in model increase 5points
> # display correct and 5 points added to user
> user_score.score += 5
> user_score.save()
> return redirect(reverse('morse_logs:incorrect'))
> else:
> # user's score declared in model has no point
> # display incorrect and 0 point added to user
> return redirect(reverse('morse_logs:incorrect'))
>
>
> ans2 = request.GET.get('ans2', '')
> if ans2 == '':
> ans2 = 0
>
> verifyGame2(int(ans2))
>
> return render(request, 'morse_logs/game2.html')
>
>
> *morse_logs/game2.html*
>
> {% extends "morse_logs/base.html" %}
>
> {% block content %}
> GAME 2
> 
> GAME 2
> 2 + 2 = ?
> 
> 
> 
> 
> 
> {% endblock content %}
>
>
> *morse_logs/correct.html*
>
> {% extends "morse_logs/base.html" %}
>
> {% block content %}
> Correct!
> 
> Congratulations! Your answer is CORRECT!
> 
> {% endblock content %}
>
>
> *morse_logs/incorrect.html*
>
> {% extends "morse_logs/base.html" %}
>
> {% block content %}
> Inorrect...
> 
> Unfortunately! Your answer is Incorrect!
> 
> {% endblock content %}
>
>
> *morse_logs/urls.py*
>
> from django.urls import path, include
> from morse_logs import views
>
> app_name = 'morse_logs'
>
> urlpatterns = [
> #The path() function is passed four arguments, two required: route and 
> view, and two optional: kwargs, and name.
> # Home Page
> path(r'', views.index, name='index'),
> # Page that shows all topics
> path(r'topics/', views.topics, name='topics'),
> path(r'cipher/', views.cipher, name='cipher'),
> path(r'decipher/', views.decipher, name='decipher'),
> path(r'tutorialIndex/', views.tutorialIndex, name='tutorialIndex'),
> path(r'gameDirectory/', views.gameDirectory, name='gameDirectory'),
> path(r'correct/', views.correct, name='correct'),
> path(r'incorrect/', views.incorrect, name='incorrect'),
> path(r'game1/', views.game1, name='game1'),
> path(r'game2/', views.game2, name='game2'),
>
> ]
>
>

-- 
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/43b5d873-fada-40ec-bd0e-fc3cfa5b6bf7%40googlegroups.com.


Re: Capture URL values in a CBV

2020-04-16 Thread Gavin Wiener
Hey Tim

The bigger question is, what are you trying to achieve? 

With the DetailView, fetching the object with the primary key is already 
handled for you, as you've seen the object will already be available in the 
template.

This website is very useful to know which functions are implemented in a 
class-based view, and which variables are available.

http://ccbv.co.uk/


On Thursday, April 16, 2020 at 8:26:00 AM UTC+8, tim042849 wrote:
>
> using django.VERSION (2, 1, 5, 'final', 0) with 
>
> python 3.7.2 on ubuntu 16.04 
>
> Given the URL pattern below:
>
> path('', ArticleDetailView.as_view(), name='article_detail'),
>
> And the view as below:
>
> class ArticleDetailView(DetailView):
> model = Article
> template_name = 'article_detail.html'
> login_url = 'login'
>
> I can access the variable pk from a template as 
>
> article.pk
>
> But I don't know how to access the pk variable from the view itself.
>
> Adding the get_queryset method to the view doesn't work
>
> example 
>
> def get_queryset(self):
> print(self.kwargs["pk"])
>
> results in 
>
> 'NoneType' object has no attribute 'filter'
>
> Trying 
> def get_object(self):
> queryset = self.filter_queryset(self.get_queryset())
> obj = queryset.get(pk=self.kwargs['pk'])
> return obj
> results in
>   'ArticleDetailView' object has no attribute 'filter_queryset'
>
> Please advise - pretty basic for django, new to me :)
> thanks
>
> -- 
> Timtj49.com
>
>

-- 
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/39595843-0a01-4ffb-95b9-46d2d3c442e3%40googlegroups.com.


Re: Models as choices

2020-04-16 Thread Gavin Wiener
Couldn't the User just have a ForeignKey on countries?

On Thursday, April 16, 2020 at 12:52:07 PM UTC+8, shreehari Vaasistha L 
wrote:
>
> how can i use model x values as choices for model y ?
>
> for eg:
> class countries(models.Model):
>  country = models.CharField(max_length=200)
>
>  def __str__(self):
>  return self.country 
>
> class User(AbstractUser):
>  """User model."""
>
>  username = None
>  full_name = models.CharField(_("Full Name"), max_length=50, default="Full 
> Name") 
>  country_choices = models.CharField(choices=countries
>

-- 
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/b1d051a8-ee61-4b0a-b5e4-66d0315306fa%40googlegroups.com.


Re: Cannot Redirect to other page

2020-04-16 Thread Gavin Wiener
So the "return" inside the inner function won't automatically "trigger". 
`redirect` is a shortcut function which constructs a HttpResponseRedirect. 
At the moment, you're calling the function, and the HttpResponseRedirect 
instance is returned from the function you're not actually doing anything 
with it, you're throwing it away. You'd need to either `return verifyGame2` 
or save the response `redirect_instance = verifyGame2` and then `return 
redirect_instance` 

But your flow in this function seems very odd. Your actions are exactly the 
same regardless if it's a GET or POST. Your form's submit should be POST 
and not a GET (since you're sending data). In that case; your code should 
be looking at the request's method, if it's a GET, then render the 
game2.html, if it's a POST, then you need fetch the POST data (the answer) 
and do the processing as you've done.

It's quite unnecessary to have an inner function in this situation.

Quite a lot to improve on with this FBV.

On Wednesday, April 15, 2020 at 8:22:35 PM UTC+8, pui hei Li wrote:
>
> I am writing a view that retrieve an answer from game2.html, then check 
> the answer; if the answer is correct, the view will redirect user to 
> correct.html, if the answer is incorrect, then user will be redirected to 
> incorrect.html. 
>
> The problem now is after clicking the submit button, user won't be 
> redirected. And after clicking the submit button, the url changed from 
> localhost:8000/game2 to 
> http://localhost:8000/game2/?ans2=4&game2Answer=Submit 
>
> It seems the view is not verifying the answer, and it is also redirecting 
> user to anywhere.
>
> How do I solve it?
>
> *morse_logs/views.py*
>
> @login_required()
> def game2(request):
> """The Game2 page"""
> if request.user and not request.user.is_anonymous:
> user = request.user
>
> def verifyGame2(val1):
> user_score, created = userScore.objects.get_or_create(user=user)
>
> if val1 == 4:
> # user's score declared in model increase 5points
> # display correct and 5 points added to user
> user_score.score += 5
> user_score.save()
> return redirect(reverse('morse_logs:incorrect'))
> else:
> # user's score declared in model has no point
> # display incorrect and 0 point added to user
> return redirect(reverse('morse_logs:incorrect'))
>
>
> ans2 = request.GET.get('ans2', '')
> if ans2 == '':
> ans2 = 0
>
> verifyGame2(int(ans2))
>
> return render(request, 'morse_logs/game2.html')
>
>
> *morse_logs/game2.html*
>
> {% extends "morse_logs/base.html" %}
>
> {% block content %}
> GAME 2
> 
> GAME 2
> 2 + 2 = ?
> 
> 
> 
> 
> 
> {% endblock content %}
>
>
> *morse_logs/correct.html*
>
> {% extends "morse_logs/base.html" %}
>
> {% block content %}
> Correct!
> 
> Congratulations! Your answer is CORRECT!
> 
> {% endblock content %}
>
>
> *morse_logs/incorrect.html*
>
> {% extends "morse_logs/base.html" %}
>
> {% block content %}
> Inorrect...
> 
> Unfortunately! Your answer is Incorrect!
> 
> {% endblock content %}
>
>
> *morse_logs/urls.py*
>
> from django.urls import path, include
> from morse_logs import views
>
> app_name = 'morse_logs'
>
> urlpatterns = [
> #The path() function is passed four arguments, two required: route and 
> view, and two optional: kwargs, and name.
> # Home Page
> path(r'', views.index, name='index'),
> # Page that shows all topics
> path(r'topics/', views.topics, name='topics'),
> path(r'cipher/', views.cipher, name='cipher'),
> path(r'decipher/', views.decipher, name='decipher'),
> path(r'tutorialIndex/', views.tutorialIndex, name='tutorialIndex'),
> path(r'gameDirectory/', views.gameDirectory, name='gameDirectory'),
> path(r'correct/', views.correct, name='correct'),
> path(r'incorrect/', views.incorrect, name='incorrect'),
> path(r'game1/', views.game1, name='game1'),
> path(r'game2/', views.game2, name='game2'),
>
> ]
>
>

-- 
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/0e1cf17c-a5cf-4e58-b3de-9e243ee8ed3b%40googlegroups.com.


Filtering Data Based On Foreign Key

2019-05-21 Thread Gavin Boyle
Hi all,

I am having an issue dynamically populating form data based on the previous
selected field. In my case I have two models one which contains different
types of memberships associated to different clubs. Then I have another
model which handles registrations for individual clubs.

My problem - when the end-user is ready to sign up the form renders (I
already filter out members based on the club they originally selected) but
I need to filter the price based on the membership selected (foreign key)
of player model.

*Below is my model for the membership types:*

# Model to store clubs available memberships so members can select and
pay on registration page
class ClubMemberships(models.Model):

club_id = models.ForeignKey(ClubInfo, on_delete=models.CASCADE)
title = models.CharField(max_length=30, default='')
price = models.DecimalField(default=0.00, max_digits=6, decimal_places=2)
description = models.TextField()

def __str__(self):
return self.title


*Here is the model for the registration:*

# Model to store player information to be used for membership registration
class Player(models.Model):

club_id = models.ForeignKey(ClubInfo, on_delete=models.CASCADE)
membership_title = models.ForeignKey(ClubMemberships,
on_delete=models.CASCADE)
price = models.DecimalField(max_digits=10, decimal_places=2)
first_name = models.CharField(max_length=20)
last_name = models.CharField(max_length=20)
dob = models.DateField(max_length=8)
email = models.EmailField(max_length=50)
phone = models.CharField(max_length=12)
mobile = models.CharField(max_length=15)
emergency_contact_name = models.CharField(max_length=40)
emergency_contact_mobile = models.CharField(max_length=15)
address1 = models.CharField(max_length=30)
address2 = models.CharField(max_length=30, default='')
address3 = models.CharField(max_length=30, default='')
town = models.CharField(max_length=30)
county = models.CharField(max_length=30)
country = models.CharField(max_length=30)

def __str__(self):
return "%s %s" % (self.first_name, self.last_name)

*Form for player registration:*

# Form to accept details for members to register
class PlayerRegistrationForm(forms.ModelForm):

class Meta:
model = Player
fields = '__all__'
labels = {
'dob': 'Date of Birth'
}
widgets = {
'dob': forms.DateInput(attrs={'id': 'datepicker'})
}

def __init__(self, *args, **kwargs):
super(PlayerRegistrationForm, self).__init__(*args, **kwargs)
self.fields['club_id'].widget = forms.HiddenInput()

def load_price(self, request):
membership = request.GET.get('membership_title')
title = ClubMemberships.objects.filter(title=membership)
self.fields['price'].queryset =
ClubMemberships.objects.filter(price=title.price)


The load_price is an example of what I am trying to accomplish but cannot
get it working. I want the form to *check the membership selected* in the
*form* then *filter* the *price of that membership* and *display it in the
form*.

*Here is my form in the browser:*

[image: image.png]

Would really appreciate any help as I cannot incorporate PayPal until I can
correctly display the price.

Thanks

Gavin

-- 
__

Séanadh Ríomhphoist/_

Email Disclaimer__
**

Tá an ríomhphost seo agus 
aon chomhad a sheoltar leis faoi rún agus is lena úsáid ag an seolaí agus 
sin amháin é. Is féidir tuilleadh a léamh anseo. 
<https://www4.dcu.ie/iss/seanadh-riomhphoist.shtml>  
<https://www4.dcu.ie/iss/seanadh-riomhphoist.shtml>*
_

This e-mail and any 
files transmitted with it are confidential and are intended solely for use 
by the addressee. Read more here. 
<https://www4.dcu.ie/iss/email-disclaimer.shtml> _
*_

-- 
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/CAHZR7Jejvn2BrbY21EC_OQp1tFAye%2BvuichJn0k59OXi2R4mpQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Suggested model structure to achieve users selection of services/package

2019-04-30 Thread Gavin Boyle
I am building an application that offers different services, a user can
select and purchase specific needed packages. I want to know the best way
to create the model so that our users can select and once paid it sets the
service to active. I have one model that holds information about each
individual services which includes (Package Title / Description / Price ).
I need another model to handle what services are associated to each user
but I am unsure how to go about this.

I have created two models as shown below but unsure how I can accomplish
the above as I believe there is a better was to accomplish this.

# Model to store club information on what clubs have access to what packages
class ClubPackages(models.Model):

club_id = models.ForeignKey(ClubInfo, on_delete=models.CASCADE)
PACKAGE_STATUS = (
('0', 'Active'),
('1', 'Not Active')
)
player_register_package = models.CharField(default='1',
max_length=1, choices=PACKAGE_STATUS)
player_register_price = models.DecimalField(default=100.00,
max_digits=8, decimal_places=2)
player_register_expiry = models.DateField(default=timezone.now)
roster_package = models.CharField(default='1', max_length=1,
choices=PACKAGE_STATUS)
roster_price = models.DecimalField(default=50.00, max_digits=8,
decimal_places=2)
roster_expiry = models.DateField(default=timezone.now)
rent_a_pitch_package = models.CharField(default='1', max_length=1,
choices=PACKAGE_STATUS)
rent_a_pitch_price = models.DecimalField(default=100.00,
max_digits=8, decimal_places=2)
rent_a_pitch_expiry = models.DateField(default=timezone.now)
shop_package = models.CharField(default='1', max_length=1,
choices=PACKAGE_STATUS)
shop_price = models.DecimalField(default=50.00, max_digits=8,
decimal_places=2)
shop_expiry = models.DateField(default=timezone.now)

# Model to store our available packages
class OurPackages(models.Model):

title = models.CharField(max_length=50)
description = models.TextField(max_length=200)
price = models.DecimalField(max_digits=8, decimal_places=2)

def __str__(self):
return self.title

-- 
__

Séanadh Ríomhphoist/_

Email Disclaimer__
**

Tá an ríomhphost seo agus 
aon chomhad a sheoltar leis faoi rún agus is lena úsáid ag an seolaí agus 
sin amháin é. Is féidir tuilleadh a léamh anseo. 
  
*
_

This e-mail and any 
files transmitted with it are confidential and are intended solely for use 
by the addressee. Read more here. 
 _
*_

-- 
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/CAHZR7JeK4wqbCHVzWsH1%2BWLpgMPQTBZ5QTwePg4o%2BDpr98FNVA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Filtering choices in a form based on previous field selection

2019-04-07 Thread Gavin Boyle
Hi all,

Just quickly to summarize I have an app, which allows clubs to sign up and
carry out different tasks. One of the features is a scheduling / rosters.
Currently I have a form to add times to the roster. The club pages work off
a session key based on the initially selected club.

My form consists of:
*club_id* - which I have hidden and initialized based on the logged in user.
*pitch_id - *which is currently displaying all pitches associated to all
clubs but I need this to *only show pitches based on the foreign key for
the club_id *

Would appreciate any help.

Please see code below:

*form.py *

from django import forms
from clubkit.roster.models import RosterId
import datetime
from django.core.exceptions import ValidationError
from django.utils.translation import gettext_lazy as _


# Form to add/edit club roster
class RosterForm(forms.ModelForm):

class Meta():
model = RosterId
fields = ('club_id', 'pitch_id', 'team_id', 'date',
  'start_time', 'finish_time', 'reoccuring_event',)
widgets = {
'date': forms.DateInput(attrs={'id': 'datepicker'})
}

def clean_date(self):
date = self.clean_date['date']
if date < datetime.date.today():
raise ValidationError(_('Date cannot be in the past.'))
return date

def __init__(self, *args, **kwargs):
super(RosterForm, self).__init__(*args, **kwargs)
self.fields['club_id'].widget = forms.HiddenInput()

*model.py - for roster*

from django.db import models
from clubkit.clubs.models import ClubInfo, Pitch, Team


# Model to store roster information
class RosterId(models.Model):
club_id = models.ForeignKey(ClubInfo, on_delete=models.CASCADE)
pitch_id = models.ForeignKey(Pitch, on_delete=models.CASCADE)
team_id = models.ForeignKey(Team, on_delete=models.CASCADE)
date = models.DateField(max_length=8)
start_time = models.TimeField(default='')
finish_time = models.TimeField(default='')
reoccuring_event = models.BooleanField(default=False)

*model.py - for pitch*

class Pitch(models.Model):
club_id = models.ForeignKey(ClubInfo, on_delete=models.CASCADE,
related_name="pitches")
pitch_name = models.CharField(max_length=30)
PITCH_SIZES = (
('S', 'Small'),
('M', 'Medium'),
('L', 'Large'),
)
PITCH_TYPE = (
('1', 'Outdoor'),
('2', 'Indoor'),
)
pitch_size = models.CharField(max_length=1, choices=PITCH_SIZES)
pitch_type = models.CharField(max_length=1, choices=PITCH_TYPE)
open_time = models.TimeField(default='09:00')
close_time = models.TimeField(default='22:00')
RENT_TYPE = (
('0', 'Not Available To Rent'),
('1', 'Available To Rent'),
)
rental = models.CharField(max_length=1, choices=RENT_TYPE)
rental_price = models.DecimalField(default=0.00, max_digits=6,
decimal_places=2)
max_people = models.IntegerField(null=True)

def __str__(self):
return self.pitch_name

*view.py*

class ClubRoster(APIView):
renderer_classes = [TemplateHTMLRenderer]
template_name = 'roster.html'

# Get method to retrieve current roster information and form
def get(self, request):
if request.user.is_authenticated:
club_pk = request.session.get('pk')
club_info = ClubInfo.objects.filter(user=request.user).first()
reoccuring_event =
RosterId.objects.filter(reoccuring_event=True, club_id=club_pk)
inital_data = {
'club_id': club_info,
}
form = RosterForm(initial=inital_data)
roster = RosterId.objects.filter(club_id=club_pk)
return Response({'form': form,
 'roster': roster,
 'club_pk': club_pk,
 'reoccuring_event': reoccuring_event
 })

-- 
__

Séanadh Ríomhphoist/_

Email Disclaimer__
**

Tá an ríomhphost seo agus 
aon chomhad a sheoltar leis faoi rún agus is lena úsáid ag an seolaí agus 
sin amháin é. Is féidir tuilleadh a léamh anseo. 
  
*
_

This e-mail and any 
files transmitted with it are confidential and are intended solely for use 
by the addressee. Read more here. 
 _
*_

-- 
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/CAHZR7JdQjz6AaXVsrUJxhFs2SD6mm381ybfS%2Bqbeqh%2B%3D3SvwaA%40mail.gmail.com.
For more options, visit https:

Using sessions key variables as a url argument

2019-03-10 Thread Gavin Boyle
Hi all,

I am not sure if this is possible as I could find nothing online but would
appreciate any alternative solution.

   - In my view I obtain a pk which is set as a session key
   - I need to pass that session key variable into the url argument.

e.g. http://127.0.0.1:8000/club_home//teams/

Code below, any other samples of code needed let me know

Thanks
Gav

*Main Urls*

urlpatterns = [
url('admin/', admin.site.urls),
url(r'^club_home/', include('clubkit.clubs.urls'), name='clubs'),
]

*Urls.py*

urlpatterns = [
path('', views.club_home, name='club_home'),
path('teams/', views.TeamInfo.as_view(), name='teams'),
path('pitches/', views.PitchInfo.as_view(), name='pitches'),
]

*View.py:*

def club_home(request, pk=None):
if pk:
request.session['pk'] = pk
club = ClubInfo.objects.filter(pk=pk)
club_posts = ClubPosts.objects.filter(club_id=club[0])
else:
club_pk = request.session.get('pk')
club = ClubInfo.objects.filter(pk=club_pk)
club_posts = ClubPosts.objects.filter(club_id=club[0])
args = {'club': club,
'club_posts': club_posts
}
return render(request, 'club_home_page.html', args)

-- 
__

Séanadh Ríomhphoist/_

Email Disclaimer__
**

Tá an ríomhphost seo agus 
aon chomhad a sheoltar leis faoi rún agus is lena úsáid ag an seolaí agus 
sin amháin é. Is féidir tuilleadh a léamh anseo. 
  
*
_

This e-mail and any 
files transmitted with it are confidential and are intended solely for use 
by the addressee. Read more here. 
 _
*_

-- 
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/CAHZR7Jfbaf91WFE47EaqqjNch3dqVd-_9%2BLd8FUAPcuNOBFhww%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Using signals to populate another model based on new registered user

2019-03-09 Thread Gavin Boyle
Hi all,

I am new to working with signals and triggers, what I am trying to
accomplish is:

   1. When a new user registers, I have another model to deal with
   subscriptions.
   2. I want to create an instance for that subscription model with all the
   default values based on the new user.
   3. Otherwise no object is created in this model and it has to be done
   via a form.

Would appreciate any help and if any other code is needed let me know.

*See code below:*

*Form part of user registration:*

class ClubInfoForm(forms.ModelForm):
club_address2 = forms.CharField(required=False)
club_address3 = forms.CharField(required=False)

class Meta():
model = ClubInfo
fields = ('club_name', 'club_logo', 'club_address1', 'club_address2',
  'club_address3', 'club_town', 'club_county', 'club_country',)

def clean_club_name(self):
club_name = self.cleaned_data['club_name']
if ClubInfo.objects.filter(club_name=club_name).exists():
raise ValidationError(_("Club already exists"))
return club_name

*Views for registration:*

def register(request):
registered = False
if request.method == 'POST':
user_form = UserForm(data=request.POST)
profile_form = ClubInfoForm(data=request.POST)
if user_form.is_valid() and profile_form.is_valid():
user = user_form.save()
user.set_password(user.password)
user.save()
profile = profile_form.save(commit=False)
profile.user = user
if 'profile_pic' in request.FILES:
print('found it')
profile.profile_pic = request.FILES['profile_pic']
profile.save()
registered = True
else:
print(user_form.errors, profile_form.errors)
else:
user_form = UserForm()
profile_form = ClubInfoForm()
return render(request,
  'registration.html',
  {'user_form': user_form,
   'profile_form': profile_form,
   'registered': registered})


*Models for club info used upon registration and the model I want to update
when a new user is created:*

class ClubInfo(models.Model):

user = models.OneToOneField(User, on_delete=models.CASCADE)
club_name = models.CharField(max_length=50, default='', unique=True)
club_logo = models.ImageField(upload_to='profile_pics', blank=True)
club_address1 = models.CharField(max_length=30)
club_address2 = models.CharField(max_length=30, default='')
club_address3 = models.CharField(max_length=30, default='')
club_town = models.CharField(max_length=30)
club_county = models.CharField(max_length=30)
club_country = models.CharField(max_length=30)
created_date = models.DateTimeField(default=timezone.now)

def set_default_packages(sender, **kwargs):
if kwargs['created']:
ClubPackages.objects.create(club_id=kwargs['instance'])

post_save.connect(set_default_packages, sender=club_name)

def __str__(self):
return self.club_name


class ClubPackages(models.Model):

club_id = models.ForeignKey(ClubInfo, on_delete=models.CASCADE)
PACKAGE_STATUS = (
('0', 'Active'),
('1', 'Not Active')
)
player_register_package = models.CharField(default='1',
max_length=1, choices=PACKAGE_STATUS)
player_register_price = models.DecimalField(default=100.00,
max_digits=8, decimal_places=2)
player_register_expiry = models.DateField(default=timezone.now)
roster_package = models.CharField(default='1', max_length=1,
choices=PACKAGE_STATUS)
roster_price = models.DecimalField(default=50.00, max_digits=8,
decimal_places=2)
roster_expiry = models.DateField(default=timezone.now)
rent_a_pitch_package = models.CharField(default='1', max_length=1,
choices=PACKAGE_STATUS)
rent_a_pitch_price = models.DecimalField(default=100.00,
max_digits=8, decimal_places=2)
rent_a_pitch_expiry = models.DateField(default=timezone.now)
shop_package = models.CharField(default='1', max_length=1,
choices=PACKAGE_STATUS)
shop_price = models.DecimalField(default=50.00, max_digits=8,
decimal_places=2)
shop_expiry = models.DateField(default=timezone.now).

-- 
__

Séanadh Ríomhphoist/_

Email Disclaimer__
**

Tá an ríomhphost seo agus 
aon chomhad a sheoltar leis faoi rún agus is lena úsáid ag an seolaí agus 
sin amháin é. Is féidir tuilleadh a léamh anseo. 
  
*
_

This e-mail and any 
files transmitted with it are confidential and are intended solely for use 
by the addressee. Read more here. 
 _
*_

-- 
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+un

Re: Working with pk arguments within an included URL

2019-02-21 Thread Gavin Boyle
Hi Simon.

Worked perfectly appreciate all your help, such a weight off my shoulders
now.

Thanks

Gavin

On Mon, 18 Feb 2019 at 09:39, Gavin Boyle  wrote:

> Perfect Simon. I’ll give it a go.
>
> Appreciate your help.
>
> Gavin
>
> On Mon, 18 Feb 2019 at 08:10, Simon A  wrote:
>
>> Hi Gavin,
>>
>> Please see this one.
>> https://docs.djangoproject.com/en/2.1/topics/http/sessions/. It first
>> needs to be setup in your settings.py.
>>
>> Basically, this is just a field in the database that gets retrieved
>> whenever you want.
>>
>> # set a session variable
>> self.request.session['key'] = 'value'
>>
>> # get a session variable
>> self.request.session.get('key', None)
>>
>> On Mon, Feb 18, 2019 at 3:10 PM Gavin Boyle 
>> wrote:
>>
>>> Hi Simon,
>>>
>>> That’s a great idea, I’ve only ever worked with built in sessions for
>>> logging in. Would you have a link to some documentation or an example that
>>> would help me as I’m relatively new to Django and this has been holding me
>>> back months now.
>>>
>>> Thanks
>>>
>>> Gavin
>>>
>>> On Mon, 18 Feb 2019 at 04:11, Simon A  wrote:
>>>
>>>> I think I had a similar scenario a few weeks ago. One option that you
>>>> have is to store the originally selected PK to the session object. Whenever
>>>> you load a page, for you can retrieve the PK from the session object. Most
>>>> likely you'll do this on the get_queryset function
>>>>
>>>>
>>>> On Sunday, February 17, 2019 at 8:24:53 PM UTC+8, GavinB841 wrote:
>>>>>
>>>>> Hi,
>>>>>
>>>>> To briefly explained:
>>>>>
>>>>>- I have a main site which provides links to multiple sports club
>>>>>pages.
>>>>>- Currently once clicked it opens the club home page and displays
>>>>>information based on that club by passing in the pk.
>>>>>- I then have many other pages associated to the clubs. e.g.
>>>>>Teams, Player Registration, Shop etc.
>>>>>- But when I click on the navbar for example "Player Registration"
>>>>>I have no idea how to continue the URL with the originally selected PK 
>>>>> and
>>>>>how to use that PK in the view.
>>>>>
>>>>>
>>>>> ***Current I have these pages working off the authenticated user but
>>>>> realistically I want it working off the originally selected club***
>>>>>
>>>>> I am not sure how to write the view to allow for this to work and then
>>>>> pass the pk argument into the nav bar url simiarlary how I did it on the
>>>>> main site:
>>>>>
>>>>> 
>>>>>
>>>>>
>>>>> Would really appreciate any help been stuck on this for a few months
>>>>> now.
>>>>>
>>>>> Below is an example of the Clubs Teams I need this to work for:
>>>>>
>>>>> *Urls.py:*
>>>>>
>>>>> urlpatterns = [
>>>>> path('', views.club_home, name='club_home'),
>>>>> path('/', include([
>>>>> path('home/', views.club_home, name='club_home_with_pk'),
>>>>> path('teams/', views.TeamInfo.as_view(), name='teams'),
>>>>> ])),
>>>>>
>>>>>
>>>>> *Nav bar for club pages:*
>>>>>
>>>>> Home
>>>>> Team
>>>>> Pitches
>>>>> Memberships
>>>>>
>>>>>
>>>>>
>>>>> *Views.py*
>>>>>
>>>>>
>>>>> def club_home(request, pk=None):
>>>>> if pk:
>>>>> club = ClubInfo.objects.filter(pk=pk)
>>>>> club_posts = ClubPosts.objects.filter(club_id=club[0])
>>>>> elif request.user.is_authenticated:
>>>>> club = ClubInfo.objects.filter(user=request.user)
>>>>> club_posts = ClubPosts.objects.filter(club_id=club[0])
>>>>> # photo = model.club_logo.ImageField(storage=profile_pics)
>>>>> args = {'club': club,
>>>>> 'club_posts': club_posts
>>>>&g

Re: Working with pk arguments within an included URL

2019-02-18 Thread Gavin Boyle
Perfect Simon. I’ll give it a go.

Appreciate your help.

Gavin

On Mon, 18 Feb 2019 at 08:10, Simon A  wrote:

> Hi Gavin,
>
> Please see this one.
> https://docs.djangoproject.com/en/2.1/topics/http/sessions/. It first
> needs to be setup in your settings.py.
>
> Basically, this is just a field in the database that gets retrieved
> whenever you want.
>
> # set a session variable
> self.request.session['key'] = 'value'
>
> # get a session variable
> self.request.session.get('key', None)
>
> On Mon, Feb 18, 2019 at 3:10 PM Gavin Boyle 
> wrote:
>
>> Hi Simon,
>>
>> That’s a great idea, I’ve only ever worked with built in sessions for
>> logging in. Would you have a link to some documentation or an example that
>> would help me as I’m relatively new to Django and this has been holding me
>> back months now.
>>
>> Thanks
>>
>> Gavin
>>
>> On Mon, 18 Feb 2019 at 04:11, Simon A  wrote:
>>
>>> I think I had a similar scenario a few weeks ago. One option that you
>>> have is to store the originally selected PK to the session object. Whenever
>>> you load a page, for you can retrieve the PK from the session object. Most
>>> likely you'll do this on the get_queryset function
>>>
>>>
>>> On Sunday, February 17, 2019 at 8:24:53 PM UTC+8, GavinB841 wrote:
>>>>
>>>> Hi,
>>>>
>>>> To briefly explained:
>>>>
>>>>- I have a main site which provides links to multiple sports club
>>>>pages.
>>>>- Currently once clicked it opens the club home page and displays
>>>>information based on that club by passing in the pk.
>>>>- I then have many other pages associated to the clubs. e.g. Teams,
>>>>Player Registration, Shop etc.
>>>>- But when I click on the navbar for example "Player Registration"
>>>>I have no idea how to continue the URL with the originally selected PK 
>>>> and
>>>>how to use that PK in the view.
>>>>
>>>>
>>>> ***Current I have these pages working off the authenticated user but
>>>> realistically I want it working off the originally selected club***
>>>>
>>>> I am not sure how to write the view to allow for this to work and then
>>>> pass the pk argument into the nav bar url simiarlary how I did it on the
>>>> main site:
>>>>
>>>> 
>>>>
>>>>
>>>> Would really appreciate any help been stuck on this for a few months
>>>> now.
>>>>
>>>> Below is an example of the Clubs Teams I need this to work for:
>>>>
>>>> *Urls.py:*
>>>>
>>>> urlpatterns = [
>>>> path('', views.club_home, name='club_home'),
>>>> path('/', include([
>>>> path('home/', views.club_home, name='club_home_with_pk'),
>>>> path('teams/', views.TeamInfo.as_view(), name='teams'),
>>>> ])),
>>>>
>>>>
>>>> *Nav bar for club pages:*
>>>>
>>>> Home
>>>> Team
>>>> Pitches
>>>> Memberships
>>>>
>>>>
>>>>
>>>> *Views.py*
>>>>
>>>>
>>>> def club_home(request, pk=None):
>>>> if pk:
>>>> club = ClubInfo.objects.filter(pk=pk)
>>>> club_posts = ClubPosts.objects.filter(club_id=club[0])
>>>> elif request.user.is_authenticated:
>>>> club = ClubInfo.objects.filter(user=request.user)
>>>> club_posts = ClubPosts.objects.filter(club_id=club[0])
>>>> # photo = model.club_logo.ImageField(storage=profile_pics)
>>>> args = {'club': club,
>>>> 'club_posts': club_posts
>>>> }
>>>> return render(request, 'club_home_page.html', args)
>>>>
>>>>
>>>> class TeamInfo(APIView):
>>>> renderer_classes = [TemplateHTMLRenderer]
>>>> template_name = 'teams.html'
>>>>
>>>> def get(self, request):
>>>> form = TeamForm()
>>>> user = ClubInfo.objects.filter(user=request.user).first()
>>>> teams = Team.objects.filter(club_id=user.pk)
>>>> retur

Re: Working with pk arguments within an included URL

2019-02-17 Thread Gavin Boyle
Hi Simon,

That’s a great idea, I’ve only ever worked with built in sessions for
logging in. Would you have a link to some documentation or an example that
would help me as I’m relatively new to Django and this has been holding me
back months now.

Thanks

Gavin

On Mon, 18 Feb 2019 at 04:11, Simon A  wrote:

> I think I had a similar scenario a few weeks ago. One option that you have
> is to store the originally selected PK to the session object. Whenever you
> load a page, for you can retrieve the PK from the session object. Most
> likely you'll do this on the get_queryset function
>
>
> On Sunday, February 17, 2019 at 8:24:53 PM UTC+8, GavinB841 wrote:
>>
>> Hi,
>>
>> To briefly explained:
>>
>>- I have a main site which provides links to multiple sports club
>>pages.
>>- Currently once clicked it opens the club home page and displays
>>information based on that club by passing in the pk.
>>- I then have many other pages associated to the clubs. e.g. Teams,
>>Player Registration, Shop etc.
>>- But when I click on the navbar for example "Player Registration" I
>>have no idea how to continue the URL with the originally selected PK and
>>how to use that PK in the view.
>>
>>
>> ***Current I have these pages working off the authenticated user but
>> realistically I want it working off the originally selected club***
>>
>> I am not sure how to write the view to allow for this to work and then
>> pass the pk argument into the nav bar url simiarlary how I did it on the
>> main site:
>>
>> 
>>
>>
>> Would really appreciate any help been stuck on this for a few months now.
>>
>> Below is an example of the Clubs Teams I need this to work for:
>>
>> *Urls.py:*
>>
>> urlpatterns = [
>> path('', views.club_home, name='club_home'),
>> path('/', include([
>> path('home/', views.club_home, name='club_home_with_pk'),
>> path('teams/', views.TeamInfo.as_view(), name='teams'),
>> ])),
>>
>>
>> *Nav bar for club pages:*
>>
>> Home
>> Team
>> Pitches
>> Memberships
>>
>>
>>
>> *Views.py*
>>
>>
>> def club_home(request, pk=None):
>> if pk:
>> club = ClubInfo.objects.filter(pk=pk)
>> club_posts = ClubPosts.objects.filter(club_id=club[0])
>> elif request.user.is_authenticated:
>> club = ClubInfo.objects.filter(user=request.user)
>> club_posts = ClubPosts.objects.filter(club_id=club[0])
>> # photo = model.club_logo.ImageField(storage=profile_pics)
>> args = {'club': club,
>> 'club_posts': club_posts
>> }
>> return render(request, 'club_home_page.html', args)
>>
>>
>> class TeamInfo(APIView):
>> renderer_classes = [TemplateHTMLRenderer]
>> template_name = 'teams.html'
>>
>> def get(self, request):
>> form = TeamForm()
>> user = ClubInfo.objects.filter(user=request.user).first()
>> teams = Team.objects.filter(club_id=user.pk)
>> return Response({'form': form,
>>  'teams': teams,
>>  })
>>
>> def post(self, request):
>> form = TeamForm(data=request.data)
>> user = ClubInfo.objects.filter(user=request.user).first()
>> teams = Team.objects.filter(club_id=user.pk)
>> if form.is_valid():
>> form.save()
>> return Response({'form': form,
>>  'teams': teams
>>  })
>>
>>
>>
>> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/django-users/KsvZHK1z6BI/unsubscribe.
> To unsubscribe from this group and all its topics, 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/c508e2ee-d73a-4a02-923d-d033e467efe3%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/c508e2ee-d73a-4a02-923d-d033e467efe3%40googlegroups.com?utm_medium=email&utm_source=foot

Re: Passing pk arguments from a URL into another view

2019-02-04 Thread Gavin Boyle
Hi Pooya,

Once I’ve done the include, how can I then pass that PK into the view of
the included urls?

Thanks
Gavin

On Mon, 4 Feb 2019 at 08:15, Ivan Martić  wrote:

> Can you elaborate a bit, i have the same issue with noreverse error
>
> ned, 3. velj 2019. u 15:08 poOya mOsaddegh 
> napisao je:
>
>> Hi
>> You may use include in urls.py
>>
>> urlpatterns = [
>> path('', views.club_home, name='club_home'),
>> path('/', include(club_home_urls, namespace='club_home')),
>> ]
>>
>>
>>
>> On Sat, Feb 2, 2019 at 8:20 PM GavinB841 
>> wrote:
>>
>>> *Hi all,*
>>>
>>> *I am having issues using arguments from a URL in another view, I have
>>> reached out on stackover flow with no success, i believe i am wording this
>>> question poorly.*
>>>
>>> *To quickly explain *
>>>
>>>- *I have a main site which shows a list of sports clubs. When the
>>>user selects on one it renders that specific club home page using the PK
>>>passed in the template.*
>>>- *Once I get to this home page
>>>e.g. http://127.0.0.1:8000/club_home/2/
>>><http://127.0.0.1:8000/club_home/2/>  .  I have many sub-pages which a 
>>> user
>>>can select but I have no idea how I can use that same PK to filter data 
>>> in
>>>the other pages to only show details based on that club.*
>>>- *I would also like to include that PK in the rest of the URLs.
>>>e.g. http://127.0.0.1:8000/club_home/2/teams/
>>><http://127.0.0.1:8000/club_home/2/teams/>*
>>>
>>>
>>> *Code:*
>>>
>>> *index.html:*
>>>
>>> Our Clubs
>>> {% for club in all_clubs %}
>>> 
>>> {{ club.club_name }}
>>> 
>>>   {% endfor %}
>>>
>>>
>>> *urls.py*
>>>
>>> I understand I must include the / before teams in the URL
>>> but I am unsure how to pass in that argument
>>>
>>> urlpatterns = [
>>> path('', views.club_home, name='club_home'),
>>> path('/', views.club_home, name='club_home_with_pk'),
>>> path('teams/', views.TeamInfo.as_view(), name='teams'),
>>> ]
>>>
>>>
>>>
>>>
>>>
>>> *views.py *
>>>
>>>
>>>
>>> def club_home(request, pk=None):
>>> if pk:
>>> club = ClubInfo.objects.filter(pk=pk)
>>> club_posts = ClubPosts.objects.filter(club_id=club[0])
>>> elif request.user.is_authenticated:
>>> club = ClubInfo.objects.filter(user=request.user)
>>> club_posts = ClubPosts.objects.filter(club_id=club[0])
>>> # photo = model.club_logo.ImageField(storage=profile_pics)
>>> args = {'club': club,
>>> 'club_posts': club_posts
>>> }
>>> return render(request, 'club_home_page.html', args)
>>>
>>>
>>>
>>> class TeamInfo(APIView):
>>> renderer_classes = [TemplateHTMLRenderer]
>>> template_name = 'teams.html'
>>>
>>> def get(self, request):
>>> serializer = TeamSerializer()
>>> user = ClubInfo.objects.filter(user=request.user).first()
>>> teams = Team.objects.filter(club_id=user.pk)
>>> return Response({'serializer': serializer,
>>>  'teams': teams,
>>>  })
>>>
>>>
>>>
>>> *club_main_page.html*
>>>
>>>
>>> navbar on club home page to get to other pages, I know I need to 
>>> include  into the **URL and** I need to pass this argument into the 
>>> href of this URL but as need to figure out the view before adding this 
>>>
>>>
>>>
>>> Team
>>>
>>>
>>>
>>> *Any idea what I need to add into the view to allow for this. I would 
>>> really appreciate any help as I've been stuck on this for weeks now. *
>>>
>>>
>>> *Thanks *
>>>
>>>
>>> *Gavin*
>>>
>>>
>>>
>>> *Séanadh Ríomhphoist/Email DisclaimerTá an ríomhphost seo agus aon
>>> chomhad a sheoltar leis faoi rún agus is lena úsáid ag an seolaí agus sin
>>> amháin é.

Re: Writing your first Django app, part 5 Testing

2015-02-21 Thread Gavin Patrick McCoy
Ok. I get you. Thanks very much!

On Saturday, 21 February 2015 11:56:50 UTC, Daniel Roseman wrote:
>
> You're doing this in the shell, which uses your devv database in which you 
> have obviously defined a poll already. 
>
> The docs are taking about running this in a unit test, which would create 
> a blank db without any polls. 
> -- 
> DR.

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/408cefd6-b563-43a6-ae3f-29554e8b17cc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Writing your first Django app, part 5 Testing

2015-02-21 Thread Gavin Patrick McCoy
I got a code 200. Thanks for your reply.

On Saturday, 21 February 2015 11:05:35 UTC, 严超 wrote:
>
> I think the purpose here is to test reverse() function. As long as you 
> got code 200, it's ok whatever html it returns.
> Is it right ?
>
> *Best Regards!*
>
>
> *Chao Yan--About me : http://about.me/chao_yan 
> <http://about.me/chao_yan>*
>
> *My twitter: @yanchao727 <https://twitter.com/yanchao727>*
> *My Weibo: http://weibo.com/herewearenow <http://weibo.com/herewearenow>*
> *--*
>  
> 2015-02-21 18:41 GMT+08:00 Gavin Patrick McCoy  >:
>
>> Hi, 
>>
>> I'm on part 5 of the polls tutorial (
>> https://docs.djangoproject.com/en/1.7/intro/tutorial05/) and I am 
>> running Django 1.7 and Python 3.4 on Windows 8. Just want to make sure I'm 
>> on the right track.
>>
>> For the following part of tutorial:
>>
>> >>> # get a response from '/'>>> response = client.get('/')>>> # we should 
>> >>> expect a 404 from that address>>> response.status_code404>>> # on the 
>> >>> other hand we should expect to find something at '/polls/'>>> # we'll 
>> >>> use 'reverse()' rather than a hardcoded URL>>> from 
>> >>> django.core.urlresolvers import reverse>>> response = 
>> >>> client.get(reverse('polls:index'))>>> response.status_code200>>> 
>> >>> response.content'\n\n\nNo polls are available.\n\n' 
>> >>> *<-Not getting this. See below. Seeing What's up?*>>> # note - you 
>> >>> might get unexpected results if your ``TIME_ZONE``>>> # in 
>> >>> ``settings.py`` is not correct. If you need to change it,>>> # you will 
>> >>> also need to restart your shell session>>> from polls.models import 
>> >>> Question>>> from django.utils import timezone>>> # create a Question and 
>> >>> save it>>> q = Question(question_text="Who is your favorite Beatle?", 
>> >>> pub_date=timezone.now())>>> q.save()>>> # check the response once 
>> >>> again>>> response = client.get('/polls/')>>> response.content'\n\n\n
>> >>> \n\nWho is your favorite 
>> >>> Beatle?\n\n    \n\n' *Seeing What's up? here too.*
>> >>> # If the following doesn't work, you probably omitted the call to>>> # 
>> >>> setup_test_environment() described above>>> 
>> >>> response.context['latest_question_list'][> >>> Beatle?>] *Seeing What's up? here too*
>>
>>
>> Instead of getting '\n\n\nNo polls are available.\n\n' , the 
>> What's up poll is coming up i.e. b'r\n\t\r\n\t\r\n\t\t> href="/polls/1/">What'se up?\r\n\t\r\n\t\r\n? The rest of 
>> the code works fine as in adding the Beatles question but the What's up? 
>> question is also coming up along with the Beatles question. Is this ok? Any 
>> help would be greatly appreciated.
>>
>> Thanks,
>>
>> Gavin
>>
>>  -- 
>> 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...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com 
>> .
>> Visit this group at http://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/fc23070f-8f90-4c4c-925a-94c24d3ee8bf%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/fc23070f-8f90-4c4c-925a-94c24d3ee8bf%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/24834d06-e86a-4221-af71-5a250715076d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Writing your first Django app, part 5 Testing

2015-02-21 Thread Gavin Patrick McCoy
Hi, 

I'm on part 5 of the polls tutorial 
(https://docs.djangoproject.com/en/1.7/intro/tutorial05/) and I am running 
Django 1.7 and Python 3.4 on Windows 8. Just want to make sure I'm on the 
right track.

For the following part of tutorial:

>>> # get a response from '/'>>> response = client.get('/')>>> # we should 
>>> expect a 404 from that address>>> response.status_code404>>> # on the other 
>>> hand we should expect to find something at '/polls/'>>> # we'll use 
>>> 'reverse()' rather than a hardcoded URL>>> from django.core.urlresolvers 
>>> import reverse>>> response = client.get(reverse('polls:index'))>>> 
>>> response.status_code200>>> response.content'\n\n\nNo polls are 
>>> available.\n\n' *<-Not getting this. See below. Seeing What's 
>>> up?*>>> # note - you might get unexpected results if your ``TIME_ZONE``>>> 
>>> # in ``settings.py`` is not correct. If you need to change it,>>> # you 
>>> will also need to restart your shell session>>> from polls.models import 
>>> Question>>> from django.utils import timezone>>> # create a Question and 
>>> save it>>> q = Question(question_text="Who is your favorite Beatle?", 
>>> pub_date=timezone.now())>>> q.save()>>> # check the response once again>>> 
>>> response = client.get('/polls/')>>> response.content'\n\n\n\n\n 
>>>Who is your favorite Beatle?\n
>>> \n\n\n' *Seeing What's up? here too.*
>>> # If the following doesn't work, you probably omitted the call to>>> # 
>>> setup_test_environment() described above>>> 
>>> response.context['latest_question_list'][>> Beatle?>] *Seeing What's up? here too*


Instead of getting '\n\n\nNo polls are available.\n\n' , the What's 
up poll is coming up i.e. b'r\n\t\r\n\t\r\n\t\tWhat'se up?\r\n\t\r\n\t\r\n? The rest of the 
code works fine as in adding the Beatles question but the What's up? question 
is also coming up along with the Beatles question. Is this ok? Any help would 
be greatly appreciated.

Thanks,

Gavin

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/fc23070f-8f90-4c4c-925a-94c24d3ee8bf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Writing your first Django app, part 1 - Django 1.7 - # Make sure our __str__() addition worked.

2015-02-04 Thread Gavin Patrick McCoy
Sorry about that. Thanks a million for your reply.

On Wednesday, 4 February 2015 17:38:16 UTC, Vijay Khemlani wrote:
>
> The method is called "__str__" (note the double underscore at both ends)
>
> On Wed, Feb 4, 2015 at 2:29 PM, Gavin Patrick McCoy  > wrote:
>
>> Hi,
>>
>> Just started learning Django today. I got down to the last grey box of 
>> code on 
>> https://docs.djangoproject.com/en/1.7/intro/tutorial01/#writing-your-first-django-app-part-1
>>  and 
>> when I checked to see of the __str__() addition to models.py worked, it 
>> didn't. I didn't get [], I got [> Question object>]. I tried creating a new question again and did but now 
>> I get  [, ]. I 
>> then tried 'the three-step guide to making model changes: Change your 
>> models (in models.py). Run python manage.py makemigrations 
>> <https://docs.djangoproject.com/en/1.7/ref/django-admin/#django-admin-makemigrations>
>>  
>> to create migrations for those changes. Run python manage.py migrate 
>> <https://docs.djangoproject.com/en/1.7/ref/django-admin/#django-admin-migrate>
>>  
>> to apply those changes to the database.' I still got  [> Question object>, ]. Any ideas? Any help 
>> would be greatly appreciated. 
>>
>> Thanks, Gavin
>>
>> My models.py looks like this: 
>>
>> import datetime
>> from django.db import models
>> from django.utils import timezone
>> # Create your models here.
>> class Question(models.Model):
>> question_text = models.CharField(max_length=200)
>> pub_date = models.DateTimeField('date published')
>> 
>> def _str_(self):
>> return self.question_text
>> 
>> def was_published_recently(self):
>> return self.pub_date >= timezone.now() - 
>> datetime.timedelta(days=1)
>> 
>> class Choice(models.Model):
>> question = models.ForeignKey(Question)
>> choice_text = models.CharField(max_length=200)
>> votes = models.IntegerField(default=0)
>> def __str(self):
>> return self.choice_text
>>
>> -- 
>> 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...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com 
>> .
>> Visit this group at http://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/e518a27e-da82-4c93-884f-a7a941d23853%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/e518a27e-da82-4c93-884f-a7a941d23853%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/6acc2808-2fe9-4643-9d17-c5eaec00e592%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Writing your first Django app, part 1 - Django 1.7 - # Make sure our __str__() addition worked.

2015-02-04 Thread Gavin Patrick McCoy
Hi,

Just started learning Django today. I got down to the last grey box of code 
on 
https://docs.djangoproject.com/en/1.7/intro/tutorial01/#writing-your-first-django-app-part-1
 and 
when I checked to see of the __str__() addition to models.py worked, it 
didn't. I didn't get [], I got []. I tried creating a new question again and did but now I get  
[, ]. I then tried 'the 
three-step guide to making model changes: Change your models (in models.py). 
Run python manage.py makemigrations 
<https://docs.djangoproject.com/en/1.7/ref/django-admin/#django-admin-makemigrations>
 
to create migrations for those changes. Run python manage.py migrate 
<https://docs.djangoproject.com/en/1.7/ref/django-admin/#django-admin-migrate> 
to apply those changes to the database.' I still got  [, ]. Any ideas? Any help would be greatly 
appreciated. 

Thanks, Gavin

My models.py looks like this: 

import datetime
from django.db import models
from django.utils import timezone
# Create your models here.
class Question(models.Model):
question_text = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')

def _str_(self):
return self.question_text

def was_published_recently(self):
return self.pub_date >= timezone.now() - datetime.timedelta(days=1)

class Choice(models.Model):
question = models.ForeignKey(Question)
choice_text = models.CharField(max_length=200)
votes = models.IntegerField(default=0)
def __str(self):
return self.choice_text

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/e518a27e-da82-4c93-884f-a7a941d23853%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: admin template customization

2013-10-21 Thread Gavin Lowry
I had, but my path was wrong. Thanks for pointing me in the right direction.

On Friday, October 18, 2013 9:20:38 PM UTC-6, Timothy W. Cook wrote:
>
> Did you add:
>  TEMPLATE_DIRS = [os.path.join(BASE_DIR, 'templates')]
>
> to settings.py ?
>
>
> On Fri, Oct 18, 2013 at 6:47 PM, Gavin Lowry 
> > wrote:
>
>> I'm following the tutorial at
>> https://docs.djangoproject.com/en/1.5/intro/tutorial01/
>> ...I'm at the stage where I can change the template of the admin site. 
>> I'm instructed to copy base_site.html from the django source directory to a 
>> template/admin folder in my site directory. I have done this and changed 
>> the page title text. After restarting the server and clearing my cache, the 
>> title text doesn't change. It's still using the default template. Is there 
>> a step I'm missing?
>>  
>> -- 
>> 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...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com
>> .
>> Visit this group at http://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/5ef36791-1ae4-4d8a-bf18-a08bf883e36f%40googlegroups.com
>> .
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>
>
>
> -- 
> MLHIM VIP Signup: http://goo.gl/22B0U
> 
> Timothy Cook, MSc   +55 21 94711995
> MLHIM http://www.mlhim.org
> Like Us on FB: https://www.facebook.com/mlhim2
> Circle us on G+: http://goo.gl/44EV5
> Google Scholar: http://goo.gl/MMZ1o
> LinkedIn Profile:http://www.linkedin.com/in/timothywaynecook
>  

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/45042e6a-a9ef-407d-a064-c5b42ed3028a%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


admin template customization

2013-10-18 Thread Gavin Lowry
I'm following the tutorial at
https://docs.djangoproject.com/en/1.5/intro/tutorial01/
...I'm at the stage where I can change the template of the admin site. I'm 
instructed to copy base_site.html from the django source directory to a 
template/admin folder in my site directory. I have done this and changed 
the page title text. After restarting the server and clearing my cache, the 
title text doesn't change. It's still using the default template. Is there 
a step I'm missing?

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5ef36791-1ae4-4d8a-bf18-a08bf883e36f%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Android app that can post to a django server

2012-07-17 Thread gavin lyons
I have built the Django server as shown here 
http://stackoverflow.com/questions/5871730/need-a-minimal-django-file-upload-example

I have been trying to build an android app that will allow me to select 
files on my phone and post them to the the server.  All the examples i am 
finding are for posting data to a php server which i have tried to adapt 
with little success. 

If anyone has an ideas how this can be achieved that would be greatly 
appreciated

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/cRg_vULswLoJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Foreign Key Chicken/Egg Inline Fu

2012-05-30 Thread Patrick Gavin
Thanks Kurtis!

That is helpful.

-Patrick

On May 30, 1:14 pm, Kurtis Mullins  wrote:
> I just checked on my own code that does something in a different
> context but kinda performs the same check. I thought I'd share it with
> you in case it helps out at all.
>
>     def clean_title(self):
>
>         # Grab the data to verify this Title is unique to this user.
>         title = self.cleaned_data['title']
>         owner = self.request.user
>         slug = slugify(title)
>
>         # Grab all user pages query for validation
>         user_pages = AbstractPage.objects.filter(owner = owner)
>         user_pages = user_pages.exclude(pk = self.instance.pk)
>
>         # Validate Uniqueness
>         if user_pages.filter(title = title).exists():
>             raise ValidationError("The page title must be unique. It appears "
>                                   + "you already have a page with this 
> title.")
>         elif user_pages.filter(slug = slug).exists():
>             raise ValidationError("It appears that you're trying to use two "
>                                   + " pages with titles that are too 
> similar.")
>         else: return title
>
> Of course, you'd want to 'clean' the Captain boolean field and make
> sure that no other player in the same team is a captain before
> allowing it to pass. Different context, but hopefully this approach
> can help.
>
> On Wed, May 30, 2012 at 4:05 PM, Kurtis Mullins
>
>
>
>
>
>
>
>  wrote:
> > Sorry, I completely mis-read the last part of your problem. You
> > already thought about the same solution, haha. You might be able to
> > modify the Player model's clean (or save) method to prohibit any Team
> > from having more than one team captain. However, I'd probably just
> > check it in the Form you're using (outside of Admin)
>
> > On Wed, May 30, 2012 at 4:02 PM, Kurtis Mullins
> >  wrote:
> >> Unless a player can play for multiple teams (which I'm doubting since
> >> Team is a ForeignKey for a Player), why not remove that 'captain'
> >> attribute from your Team and put it into your Player model as a
> >> boolean field? You could create a ModelManager or class-level model
> >> method to grab the associated team caption if you want to access it
> >> easily. Otherwise, it's just a matter of:
>
> >> Team.objects.get('team_name').player_set.filter(captain=True) # Or
> >> something along those lines...
>
> >> Just an idea anyways :) Good luck!
>
> >> On Wed, May 30, 2012 at 2:15 PM, Patrick Gavin  wrote:
> >>> Hi-
>
> >>> I'm new to Django, but so far I think it is the bee's knees.
>
> >>> I could use some insight into a problem I'm working on.
>
> >>> Given the following...
>
> >>> -
> >>> # models.py
>
> >>> from django.db import models
>
> >>> class Team(models.Model):
> >>>    name = models.CharField(max_length=30)
>
> >>>    # captain is a player- but there can only be one captain per team.
> >>>    # null and blank are true to allow the team to be saved despite
> >>> not having a captain
> >>>    captain = models.ForeignKey('Player', related_name='team_captain',
> >>> null=True, blank=True)
>
> >>>    def __unicode__(self):
> >>>        return u'{0}'.format(self.name)
>
> >>> class Player(models.Model):
> >>>    first_name = models.CharField(max_length=20)
> >>>    last_name = models.CharField(max_length=30)
> >>>    team = models.ForeignKey('Team')
>
> >>>    def __unicode__(self):
> >>>        return u'{0} {1}'.format(self.first_name, self.last_name)
>
> >>> # admin.py
>
> >>> from league.models import *
> >>> from django.contrib import admin
>
> >>> class PlayerInline(admin.TabularInline):
> >>>    model = Player
> >>>    extra = 8
>
> >>> class TeamAdmin(admin.ModelAdmin):
> >>>    inlines = [PlayerInline]
> >>>    list_display = ('name', 'captain')
>
> >>> -
>
> >>> As is, when I create a new team in the admin interface I can add the
> >>> players inline, but I have to leave the team captain blank, save the
> >>> team, and then go back and change the team a

Foreign Key Chicken/Egg Inline Fu

2012-05-30 Thread Patrick Gavin
Hi-

I'm new to Django, but so far I think it is the bee's knees.

I could use some insight into a problem I'm working on.

Given the following...

-
# models.py

from django.db import models

class Team(models.Model):
name = models.CharField(max_length=30)

# captain is a player- but there can only be one captain per team.
# null and blank are true to allow the team to be saved despite
not having a captain
captain = models.ForeignKey('Player', related_name='team_captain',
null=True, blank=True)

def __unicode__(self):
return u'{0}'.format(self.name)

class Player(models.Model):
first_name = models.CharField(max_length=20)
last_name = models.CharField(max_length=30)
team = models.ForeignKey('Team')

def __unicode__(self):
return u'{0} {1}'.format(self.first_name, self.last_name)


# admin.py

from league.models import *
from django.contrib import admin

class PlayerInline(admin.TabularInline):
model = Player
extra = 8

class TeamAdmin(admin.ModelAdmin):
inlines = [PlayerInline]
list_display = ('name', 'captain')

-

As is, when I create a new team in the admin interface I can add the
players inline, but I have to leave the team captain blank, save the
team, and then go back and change the team and set the captain to one
of the players added previously. This is kind of a drag though.

Is there a way that I can make the team captain be automatically set
to the first player entered inline when the team is saved the first
time?

I 've thought about adding a boolean field to the Player model called
"is_captain", but I want to enforce only one captain per team. If I
were to go this route, is there a way I could make the is_captain
field default to True for the first inline entry but false for the
rest?

Thanks,

-Patrick

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: I love both Django and the Google Web Toolkit. Who else thinks tighter integration would be nice?

2008-12-17 Thread Gavin McQuillan
If you're interested in an all-python implementation, there's a project to
fork the functionality of GWT called pyjamas:
http://code.google.com/p/pyjamas/

Cheers,
-Gavin

On Tue, Dec 16, 2008 at 1:50 PM, adambossy  wrote:

>
> Thank you! I'll look into it. I would have never found this on my own.
>
>
> On Dec 16, 11:31 am, "Ian Lawrence"  wrote:
> > Hi
> > look athttp://autotest.kernel.org/
> > this is a djand and gwt application used for kernel testing. It basically
> > sets up an RPC django server which passes json into gwt.
> > It is a great app to learn how this all works
> >
> > Ian
> >
> > --http://ianlawrence.info
> >
>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Invalid block tag: render_comment_form

2008-12-17 Thread Gavin McQuillan
Florian,

I've found the following link to be helpful:

http://code.djangoproject.com/wiki/UsingFreeComment

For Django 1.0, you should replaces all instances of "free_comment*" with
just comment*, in both files and function names.

However, I'll add that I'm stuck on a similar problem.

The document asks you to use the following code to display the comment form:
{% comment_form for blog.entry object.id %}

It fails in a very similar way to what you describe. However, if you replace
'comment_form' with 'render_comment_form' you no longer get the error and
you don't get the form either.

Maybe you'll progress further than I have,

-Gavin

On Sun, Nov 30, 2008 at 8:59 AM, Florian Lindner wrote:

>
> Hello,
>
> I use the comments framework from the newest Django SVN checkout.
>
> I have in my template:
>
> {% load comments % }
> [...]
> {% render_comment_form for object %}
>
> resulting in a Invalid block tag: 'render_comment_form'
>
> I have found the same error in one other posting but no solution. What
> is wrong?
>
> Thanks,
>
> Florian
>
> >
>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Error in django.contrib.comments with {% comment_form_target %}

2008-11-28 Thread Gavin

I'm having exactly the same problem as Brandon above, only I haven't
upgraded from .96 to 1.0. This is occurring with a fresh install of
1.0.

I've tried all of the suggestions above as well as those in the linked
django ticket #8571.

Any insights?

Cheers,
-Gavin

On Oct 22, 6:43 am, Brandon Taylor <[EMAIL PROTECTED]> wrote:
> Hi Dmitry,
>
> After some digging, I found that folder as well. Now everything's
> working correctly again.
>
> Cпасибо,
> Brandon
>
> On Oct 22, 7:08 am, Dmitry Dzhus <[EMAIL PROTECTED]> wrote:
>
> > Brandon Taylor wrote:
> > > I see there is an closed ticket:http://code.djangoproject.com/ticket/8571.
> > > I have cleared out all of my .pyc files as suggested, but I'm still
> > > getting the template error. Can anyone offer any advice?
>
> > I had a similar problem which was resolved after I had cleared `urls/`
> > subdirectory (left there from previous Django version) from
> > `contrib/comments/`.
> > --
> > Happy Hacking.
>
> >http://sphinx.net.ru
> > む

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: specifying a model with a field computed from other fields

2006-03-09 Thread Gavin

thanks for the refs, i'll get reading :)


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: specifying a model with a field computed from other fields

2006-03-09 Thread Gavin

You're absolutely right, I could simply compute those values as
required. I also confess to not having very much dbase design
experience so your commentary is valuable. My question was also partly
motivated by the documentation on the _pre_save method, which seemed to
suggest it might serve my purpose.

My motivation here is there are tables other than Reimburse that will
do very similar things, but require some unique attributes. So I was
looking for a way to assess expenditures in one place, rather than
inspecting multiple tables. Of course I realise common things like
count and price belong in expenditures, bit I'm still faced with the
issue of needing to associate that expenditure with an Account. And
that means if I want to determine the status of an account I need to
look at all tables in which expenditures are being made.

Modifying Russell's model, I'll add a Order table and put price and
count into Expenditure:

-- model --

class Account(Model):
   owner = CharField()

class Order(Model):
catalogid = IntegerField()
vendor = CharField()
account = ForeignKey(Account)
expenditure = ForeignKey(Expenditure) # diff

class Reimburse(Model):
account = ForeignKey(Account)
reimburse_for = CharField()
expenditure = ForeignKey(Expenditure) # diff

class Expenditure(Model):
price = FloatField()
count = IntegerField()
account = ForeignKey(Account)

I can compute these values by inspecting both the Orders and Reimburse
tables. Is that the best way?

Comments appreciated.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: specifying a model with a field computed from other fields

2006-03-09 Thread Gavin

thanks for the reply, let me modify your example.

class Account(Model):
   owner = CharField()

class Reimburse(Model):
price = FloatField()
count = IntegerField()
account = ForeignKey(Account)
expenditure = ForeignKey(Expenditure) # diff

class Expenditure(Model):
cost = FloatField()
account = ForeignKey(Account)

the only diff is Reimburse now has a field called expenditure.

so how would the creation code work now?


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: specifying a model with a field computed from other fields

2006-03-09 Thread Gavin

Thanks for your response and sorry about the cryptic nature of the
query.

In my model I have a table class (Reimburse) that records an items'
unit price, the number of items bought and an account (a ForeignKey)
from which the cost (unit price * number of items) will be recorded
against. I want to be able to record this transaction in an
expenditures table - recording the cost and account.

I want expenditures to be a ForeignKey, but I want to create it based
on values entered (num_units * unit_cost, account).

My question: How can I create a foreign key based on the values entered
for other fields?

I hope that is clearer.

cheers,

g


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



specifying a model with a field computed from other fields

2006-03-08 Thread Gavin

Hi, I have a model in which there is a foreign key that I want created
using values from other fields. For example, I have a table `A`, with
fields `a`, `b` and foreign key `C`. I want to specify a final foreign
key field using the product `a`*`b` and value of `C`. I'm aiming at
being able to get between tables `A` and `C`.

What's a good way of doing this?

any thoughts much appreciated.

cheers,

g


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---