If Statement django template

2023-01-12 Thread 'dtdave' via Django users
I have the following relationship in a model

class Contract(models.Model):
supplier = models.ForeignKey(
Supplier,
on_delete=models.CASCADE,
verbose_name="Supplier Name",
related_name="contract_suppliers",
)

I am trying to include an if statement in my template but the following 
does not work:
{% if contract.supplier == 'IBM' %}

If I replace this with a non-foreign key item then it works fine.

Any help would be appreciated.



-- 
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/4343a170-b193-4c91-aac4-8d773404353dn%40googlegroups.com.


Restricting items to a specific user

2022-09-14 Thread 'dtdave' via Django users
I have the following models:

class AccountManager(models.Model):
account_manager = models.ForeignKey(
  settings.AUTH_USER_MODEL, 
  on_delete=models.CASCADE
)

def __str__(self):
return str(self.account_manager)

class Client(models.Model):
account_manager = models.ForeignKey(AccountManager, 
on_delete=models.CASCADE, related_name='account_manager_clients')
client = models.CharField(max_length=255)

def __str__(self):
return self.client

class Contract(models.Model):
client = models.ForeignKey(Client, on_delete=models.CASCADE, 
related_name='client_contracts')
site_name = models.CharField(max_length=255)

def __str__(self):
return self.site_name

I can restrict the clients to the specific account managers by using the 
following view"
class ClientListView(LoginRequiredMixin, ListView):
model = Client
template_name = "clients/list.html"

def get_queryset(self, *args, **kwargs):
return (
super()
.get_queryset(*args, **kwargs)
.filter(account_manager__account_manager=self.request.user)
)

However I can't seem to restrict the contracts to the account manager with 
the following view:
class AMContractDetailView(LoginRequiredMixin, DetailView):
model = Contract
template_name = 'contracts/am_contract_detail.html'

def get_queryset(self, *args, **kwargs):
return (
super()
.get_queryset(*args, **kwargs)
.filter(client__account_manager=self.request.user.id)
)
This allows account managers to see all the clients not just their own.
I know I am doing something fundamentally wrong but have got a bit lost!

Any help would be appreciated.




-- 
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/7405a8f2-bdac-4e20-b53b-3f9fefb6ea27n%40googlegroups.com.


LogIn Class Based View

2022-05-26 Thread 'dtdave' via Django users
I have this function based view which works perfectly but I would like to 
convert to a class based view but am stuck on how to do this:
This is my fbv:

def loginView(request):
if request.method == 'POST':
form = LoginForm(request.POST)
if form.is_valid():
cd = form.cleaned_data
user = authenticate(request,
   email=cd['email'],
   password=cd['password'])

if user is not None:
login(request, user)
if user.is_authenticated and user.is_client:
return redirect('clients:detail') # Go to client 
dashboard
elif user.is_authenticated and user.is_account_manager:
return redirect('accountmanagers:detail') #Go to 
account manager dashboard
else:
   return HttpResponse('Invalid login')
else:
# Invalid email or password. Handle as you wish
form = LoginForm()

return render(request, 'registration/login.html', {'form': form})

I would appreciate any help.

-- 
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/ea6c54f2-ecc0-407d-a296-e168d509a299n%40googlegroups.com.


Allocating items to users

2022-05-13 Thread 'dtdave' via Django users
I have the following code:
from django.conf import settings
from django.db import models

class AccountManager(models.Model):
account_manager = models.ForeignKey(
settings.AUTH_USER_MODEL, on_delete=models.PROTECT, null=True, 
blank=True
)

class Meta:
verbose_name = 'Account Manager'
verbose_name_plural = 'Account Managers'

def __str__(self):
return str(self.account_manager)
The view for this, effectively a profile, is as follows

from django.contrib.auth import get_user_model
from django.shortcuts import render
from django.views.generic import DetailView
from django.contrib.auth.mixins import LoginRequiredMixin

from .models import AccountManager

User = get_user_model()


class AccountManagerDetailView(LoginRequiredMixin, DetailView):
model = AccountManager
template_name = "accountmanagers/dashboard.html" 
 
def get_object(self, *args, **kwargs):
return self.request.user

And the url:
urlpatterns = [
path('detail/', views.AccountManagerDetailView.as_view(), 
name='accountmanagers'),
]
The template then shows the relevant user details but my problem is that I 
am stuck allocating the clients to the specific account manager. I know 
that I am missing the point in implementing a queryset and tieing it to 
that user.
Any help would be appreciated.

-- 
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/87ede928-7459-4031-a7a2-9edf52f8bacan%40googlegroups.com.


Model Design

2022-05-05 Thread 'dtdave' via Django users
We receive data from various third parties in their proprietary format in 
excel. We then import this into our database and our models have been 
designed around their format.
There is no option to change the way this data is received.
However, we now need to add an account manager to this data and under 
normal circumstances this would be a case of adding a foreign key to the 
data.

What would be the best method of dealing with this given that we cannot 
change the format of the data we receive nor the current models given that 
they mirror this structure.
One suggestion has been to use a generic foreign key but I am not sure how 
this would work.

Thanks in advance


-- 
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/97d1988f-b230-46a8-93dc-be583860467an%40googlegroups.com.


UpdateView Redirect

2020-08-31 Thread 'dtdave' via Django users
I have got myself into somewhat of a pickle.

Currently I have the following url structure:
path('/', views.PublisherDetailView.as_view(), 
name='publisher_detail'),
path('/update/', views.PublisherUpdateView.as_view(), 
name='publisher_update'),

In my views the following:
class PublisherUpdateView(UpdateView):
model = Publisher
template_name = "catalog/publisher_update.html"
fields = (
"name",
"address",
"city",
"state_province",
"country",
"website",
)

def get_success_url(self):
return reverse_lazy("catalog:publisher_detail", kwargs={'pk': 
self.object.id})
And the link in my template is:
Update
Everything works fine at this point.
However my url structure now need to become:
path('//', views.PublisherDetailView.as_view(), 
name='publisher_detail'),
path(/'/update/', views.PublisherUpdateView.as_view(), 
name='publisher_update'),

My question is how do I account for this in my views?
Any help would be appreciated

 

-- 
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/5f43d577-a26f-456e-a7b2-7fddabc166ccn%40googlegroups.com.


Custom User and Profile Model

2020-01-28 Thread 'dtdave' via Django users
I have created a Custom User Model and a Profile model that is created when 
a user registers with the site.

I just want some confirmation that my logic is right.

To avoid the error when creating a superuser "Custom users have no profile" 
I have put the following in my settings.py:
AUTH_PROFILE_MODULE = 'accounts.Profile'

accounts is the name of the app and Profile is the model name.

This works fine and creates a profile in the admin for the superuser. I 
just need confirmation that this is the correct way to do it.

Thanks in advance

-- 
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/f7b13ab7-8da9-4dc1-bada-686b4939317b%40googlegroups.com.


Import a float field using a script

2019-10-16 Thread 'dtdave' via Django users
I have the following field in my model:

area_hectares = models.FloatField(blank=True, null=True)

In my script for importing from a csv I seem to run into the following 
error:
could not convert string to float
The relevant part of the script is as follows:
area_hectares=float(row[6])

Could someone please show me the error of my ways as I know I am doing 
something wrong(and probably very stupid)?

Thanks in advance

-- 
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/863abb4b-3dab-4713-b2f2-6ee451b50705%40googlegroups.com.


Django Project Template

2019-09-09 Thread 'dtdave' via Django users
I have been using Django-cookiecutter to create my projects.

I have then decided that there was too much that I either didn't need or 
had  alternatives in particular having a single settings file using 
django-configurations.
The first project building from scratch worked fine so I decided to create 
a template and upload it to GitHub for future use.

This is when my problems began!

This is the structure of a simple project without any apps or separating 
environment variables for simplicities sake.

.
├── Pipfile
├── Pipfile.lock
├── manage.py
└── my_project
├── __init__.py
├── settings.py
├── urls.py
└── wsgi.py

I have amended the following files:
wsgi.py
os.environ.setdefault('DJANGO_SETTINGS_MODULE', '{{ my_project }}.settings')
manage.py
os.environ.setdefault('DJANGO_SETTINGS_MODULE', '{{ my_project }}.settings')
settings.py
ROOT_URLCONF = '{{ my_project }}.urls'
WSGI_APPLICATION = '{{ my_project }}.wsgi.application'

I have uploaded it to GitHub and designated it as a template.
The issue comes about when I try to use it.
I issue the following command:
django-admin.py startproject \
  
--template=https://github.com/my_repository/django-project-template/archive/master.zip
 
\
  --extension=py,md,env \
  project_name

When I open this project I find that the variable {{ my_project }} has not 
been pick up so for example the ROOT_URLCONF just shows .urls instead of 
project_name.urls and the situation is the same for the WSGI_APPLICATION 
and the same is true for the items in the settings.py

I am sure that the answer is both simple and obvious but for the life of me 
I cannot see the solution.

Any help or pointers would be gratefully received.
Thanks in advance

-- 
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/28b577d2-fd9f-4e24-9e4f-b383cc099fea%40googlegroups.com.


Re: What is the proper workflow before first migration?

2019-04-10 Thread 'dtdave' via Django users

To me the way I build my models is so that if anyone looked at the code 
they would see exactly what the model represented. I had a great mentor in 
Daniel Greenfield of Two Scoops Fame.
So my models would be users and then a separate model for public posts.
The you have the following in your settings 
AUTH_USER_MODEL = 'users.CustomUser'
and everything would br fine.
You could then use this users modle elsewhere.
Also I have never seen the templates done your way. You can just have a 
single:
'DIRS': [os.path.join(BASE_DIR, 'templates')],
Then you can either have your templates in under the relevant app name e.g
public_posts/templates/public_posts
or in one template folder split into the apps. Different people have there 
own ideal method so it is really up tp you.
Hope this helps

On Wednesday, 10 April 2019 13:45:27 UTC+1, Flip Matter wrote:
>
> Thank you very much for the resources! However it is installed in my 
> settings.py the exact line is...  AUTH_USER_MODEL = 
> 'public_posts.CustomUser' 
> Is there a different way to do it? This is the only way I have seen to set 
> your AUTH_USER_MODEL, or does my custom user model have to be in a 'users' 
> app?
>
>
> On Sat, Apr 6, 2019 at 10:26 AM 'dtdave' via Django users <
> django...@googlegroups.com > wrote:
>
>> The error you are getting  is because the CustomUser is not included in 
>> your settings.py
>> Because I use a separte user model my settings.py has this line in it:
>> AUTH_USER_MODEL = 'users.CustomUser'
>> I would recommend that you have your Custom User as a separate user model.
>> For  good tutorials on user models have a look at these links:
>> https://wsvincent.com/django-tips-custom-user-model/
>> https://wsvincent.com/django-login-with-email-not-username/
>> https://wsvincent.com/django-custom-user-model-tutorial/
>>
>> Django All-Auth is a good app for customising your user models:
>> https://www.intenct.nl/projects/django-allauth/
>> Hope this helps!
>>
>>
>> On Friday, 5 April 2019 15:58:19 UTC+1, silverst...@gmail.com wrote:
>>>
>>> Hello, I've been trying to make a social media site and know nothing 
>>> about django (i've been teaching myself using the documentation and 
>>> tutorials) I've had to redo the site three times and now have to do a 
>>> fourth because (even though I got AUTH_USER_MODEL in, all the forms ect. 
>>> ect. before first migration) for some reason it is saying that "Manager is 
>>> unavailable; auth.User has been swapped for public_posts.CustomUser". I 
>>> have not been able to find a decent description on exactly how work flow 
>>> NEEDS to be done. Obviously create user models and set AUTH_USER_MODEL 
>>> before first migration but what about the Manager? I made my 
>>> CustomUserManager at the same time as everything else.
>>>
>>> I tried to use django-registration, then found out they upgraded to 
>>> django_registration, couldn't find ANY documentation on it until almost a 
>>> week afterwards. So now my code is partially a bunch of tutorials and 
>>> partially old (possibly deprecated) code, is there somewhere that all of 
>>> the new stuff and how to transfer to the new stuff posted? This seems to be 
>>> the hardest part about Django, for me anyway. I've tried get_user_model 
>>> where user comes up to no avail.  I have three apps, admin_posts, 
>>> public_posts and accounts (get ready to smirk cuz this was stupid of me) I 
>>> have all my CustomUser stuff in public_posts and have everything required 
>>> by django_registration in accounts. I'm positive that was a huge fail on my 
>>> part but Where SHOULD all of the user stuff go?? I have no been able to 
>>> find anything about that anywhere everything only says ' 
>>> appname.CustomUser' (example) leading me to believe that it doesn't matter 
>>> where you put them. but since django_registration has its own requirements 
>>> and user dealings, will using django_registration and CustomUsers cancel 
>>> each other out/mess up each others managers?
>>>
>>> Everything I have done has only been in my project(s) and not in the 
>>> root dir. Also, if anyo contributors to django read this, thank you for 
>>> making such a freaking amazing framework, I mean this thing is just a pure 
>>> beauty so thank you!!! Y'all be some geniuses! I hope to be good enough to 
>>> contribute.
>>>
>>> Thank you for making it to the end and thank you for any responses.
>>> P.S I only post as a last resort, I've spent HOURS researching this to 
>>> no avail, not even a tease of an answer.

Re: What is the proper workflow before first migration?

2019-04-06 Thread 'dtdave' via Django users
The error you are getting  is because the CustomUser is not included in 
your settings.py
Because I use a separte user model my settings.py has this line in it:
AUTH_USER_MODEL = 'users.CustomUser'
I would recommend that you have your Custom User as a separate user model.
For  good tutorials on user models have a look at these links:
https://wsvincent.com/django-tips-custom-user-model/
https://wsvincent.com/django-login-with-email-not-username/
https://wsvincent.com/django-custom-user-model-tutorial/

Django All-Auth is a good app for customising your user models:
https://www.intenct.nl/projects/django-allauth/
Hope this helps!


On Friday, 5 April 2019 15:58:19 UTC+1, silverst...@gmail.com wrote:
>
> Hello, I've been trying to make a social media site and know nothing about 
> django (i've been teaching myself using the documentation and tutorials) 
> I've had to redo the site three times and now have to do a fourth because 
> (even though I got AUTH_USER_MODEL in, all the forms ect. ect. before first 
> migration) for some reason it is saying that "Manager is unavailable; 
> auth.User has been swapped for public_posts.CustomUser". I have not been 
> able to find a decent description on exactly how work flow NEEDS to be 
> done. Obviously create user models and set AUTH_USER_MODEL before first 
> migration but what about the Manager? I made my CustomUserManager at the 
> same time as everything else.
>
> I tried to use django-registration, then found out they upgraded to 
> django_registration, couldn't find ANY documentation on it until almost a 
> week afterwards. So now my code is partially a bunch of tutorials and 
> partially old (possibly deprecated) code, is there somewhere that all of 
> the new stuff and how to transfer to the new stuff posted? This seems to be 
> the hardest part about Django, for me anyway. I've tried get_user_model 
> where user comes up to no avail.  I have three apps, admin_posts, 
> public_posts and accounts (get ready to smirk cuz this was stupid of me) I 
> have all my CustomUser stuff in public_posts and have everything required 
> by django_registration in accounts. I'm positive that was a huge fail on my 
> part but Where SHOULD all of the user stuff go?? I have no been able to 
> find anything about that anywhere everything only says ' 
> appname.CustomUser' (example) leading me to believe that it doesn't matter 
> where you put them. but since django_registration has its own requirements 
> and user dealings, will using django_registration and CustomUsers cancel 
> each other out/mess up each others managers?
>
> Everything I have done has only been in my project(s) and not in the root 
> dir. Also, if anyo contributors to django read this, thank you for making 
> such a freaking amazing framework, I mean this thing is just a pure beauty 
> so thank you!!! Y'all be some geniuses! I hope to be good enough to 
> contribute.
>
> Thank you for making it to the end and thank you for any responses.
> P.S I only post as a last resort, I've spent HOURS researching this to no 
> avail, not even a tease of an answer...I'm only saying this so you know I 
> do indeed do the research required and don't want others to do  my work for 
> me but MAN I cannot find anything. Also, if any Django contributors read 
> this, Thank you for making such an amazing framework!!
>

-- 
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/5aedce0e-870b-48ea-89cb-98e7b022d66d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Signals and Profile Update

2018-09-17 Thread 'dtdave' via Django users
I have a Custom User Model and a separate Profile Model with django 
all-auth.

The following signal creates the profile for the user and then informs the 
admin that a new user has registered.

@receiver(post_save, sender=User)
def create_user_profile(sender, **kwargs):
'''Create a profile for a new user'''
if kwargs['created']:
Profile.objects.create(user=kwargs['instance'])


@receiver(post_save, sender=User)
def notify_admin(sender, instance, created, **kwargs):
'''Notify the administrator that a new user has been added.'''
if created:
subject = 'New Registration created'
message = 'A new candidate  %s has registered with the site' % 
instance.email
from_addr = 'no-re...@example.com'
recipient_list = ('ad...@example.com',)
send_mail(subject, message, from_addr, recipient_list)

This works fine and using Mailhog I get the email informing me of the new 
user.

Where I am stuck, is that I also want to inform the admin when a profile is 
updated. However, for the life of me I cannot fathom out how to do this!

Any help would be appreciated.

-- 
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/fd387ab3-5993-4c54-b60b-7b16cf122c52%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Advice on Model Structures

2018-08-14 Thread 'dtdave' via Django users
Many thanks

On Monday, 13 August 2018 22:44:05 UTC+1, mark wrote:
>
> dtdave,
>
> Basically, the model structure is how you indicated. To achieve changing 
> the content of a select once the page is loaded, you will have to do some 
> JavaScript magic. Django-select2 will do that for you, and there are other 
> django packages, or you can roll your own if it is not too complicated (ie 
> simple case - some JavaScript, a special url, and a special view for that 
> url to get the data - there are examples in github for this as well). 
> Django does not do this for you out of the box. IMO, it all depends on how 
> comfortable you are with JavaScript.
>
> Mark
>
> On Mon, Aug 13, 2018 at 9:57 AM, Mikhailo Keda  > wrote:
>
>> Create a 4 models:
>> 1. Region
>> 2. County (has a foreign key to Region)
>> 3. Office (has a foreign key to County)
>> 4. Employee (has a foreign key to Office)
>>
>> organise url by this pattern:
>> /
>>
>> check this example to handle a form - 
>> http://django-select2.readthedocs.io/en/latest/extra.html#chained-select2
>>
>> -- 
>> 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 https://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/80b180a9-2b58-4569-903e-3f1b387e3b7c%40googlegroups.com
>>  
>> 
>> .
>>
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/21ca707d-deb3-4c51-8a9e-359493b470e8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Advice on Model Structures

2018-08-14 Thread 'dtdave' via Django users
Many thanks

On Monday, 13 August 2018 17:57:03 UTC+1, Mikhailo Keda wrote:
>
> Create a 4 models:
> 1. Region
> 2. County (has a foreign key to Region)
> 3. Office (has a foreign key to County)
> 4. Employee (has a foreign key to Office)
>
> organise url by this pattern:
> /
>
> check this example to handle a form - 
> http://django-select2.readthedocs.io/en/latest/extra.html#chained-select2
>

-- 
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/7e715e3d-7549-4e7c-afff-fca8b2c63b6b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Advice on Model Structures

2018-08-13 Thread 'dtdave' via Django users
I would like some advice as the best way with dealing with the following 
model structure.
Region
Counties
Office
Employees

I would like to show the relevant counties in the relevant regions and then 
to show the office in that county followed by the employees in that office.

In the view end user would then be able to click on the region which would 
only show the associated counties and then click through to the office 
and/or the employees.

I have received conflicting advice on how to deal with this such as 
django-mptt or dependent dropdowns which has left me somewhat confused.

Any pointers as to the most effective method would be appreciated.

Thanks in advance

-- 
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/a75f494d-12d3-4e6b-9d16-31fc5bee51de%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django DateField

2018-07-09 Thread 'dtdave' via Django users
Many Thanks

On Friday, 6 July 2018 16:13:35 UTC+1, Melvyn Sopacua wrote:
>
> On vrijdag 6 juli 2018 16:46:08 CEST 'dtdave' via Django users wrote: 
> > Many thanks for the help on this. I have implemented the following: 
> > models.py 
> > start_date = models.DateField(null=True, blank=True,) 
> > asap = models.BooleanField(default=False) 
> > 
> > I have amend my manager so the order is right on the template. 
> > The template is where I am going wrong. 
> > This what I have started with in my template; 
> > {% if 'job.asap' == 'True' %} 
> > Start Date: {{job.asap}} 
>
> {% if job.asap %} 
> Start Date: {% trans "as soon as possible" %} 
> {% else %} 
>  Start Date: {{job.start_date}} 
> {% endif %} 
>
> -- 
> Melvyn Sopacua 
>

-- 
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/cea85bf9-3b83-4a3a-b436-b3e2d447c575%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django DateField

2018-07-06 Thread 'dtdave' via Django users
Many thanks for the help on this. I have implemented the following:
models.py
start_date = models.DateField(null=True, blank=True,)
asap = models.BooleanField(default=False)

I have amend my manager so the order is right on the template.
The template is where I am going wrong.
This what I have started with in my template;
{% if 'job.asap' == 'True' %}
Start Date: {{job.asap}}
{% else %}

Start Date:{{job.start_date}}
{% endif %}

The start dates are listed in the correct date order but any of those tasks 
with an ASAP start show None as the start date in the template.
I know the answer is probably obvious, but for smoe raeson I cannot fathom 
it out at the moment.
Again thanks for all the help

On Thursday, 5 July 2018 20:08:30 UTC+1, Melvyn Sopacua wrote:
>
> On donderdag 5 juli 2018 19:05:47 CEST 'dtdave' via Django users wrote: 
>
> > However, now I have been asked to change this so that some projects have 
> a 
> > start date of ASAP and others have date. 
> > These then need to be listed in my template with ASAP tasks coming first 
> > and then those with a start date coming in descending order. 
> > 
> > I am at a loss as to how to achieve this so would welcome any pointers 
> or 
> > ideas. 
>
>
> Asap field is a boolean. Date field needs to be able to be blank and null. 
> Then: 
>
> tasks = Task.objects.order_by('asap', '-start_date') 
>
> Done :) 
> -- 
> Melvyn Sopacua 
>

-- 
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/0b7f4d0c-534e-470e-ab35-be6d88acb6e8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django DateField

2018-07-05 Thread 'dtdave' via Django users
I have a model that contains a datefield which signifies the start date for 
a task.
My modelmanager filters the tasks by the start date and the template lists 
them in the date descending order. Everything is fine with this.

However, now I have been asked to change this so that some projects have a 
start date of ASAP and others have date.
These then need to be listed in my template with ASAP tasks coming first 
and then those with a start date coming in descending order.

I am at a loss as to how to achieve this so would welcome any pointers or 
ideas.
Thanks

-- 
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/fd2be4aa-408f-4221-9950-ba7a9af96e9c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django Import/Export ManyTo Many

2017-06-21 Thread 'dtdave' via Django users
I have a model with a manytomany field as follows:
  
  contact = ChainedManyToManyField(
'contacts.Contact',
chained_field="practice",
chained_model_field="practice",
)

Within my admin I have the following for import/export:

contact = fields.Field(column_name='contact name', attribute='contact',
   widget=ManyToManyWidget(Contact, 'contact'))

However, this only returns the contact id.
I am stuck on how I could return the name of the contact instead. Within 
the contact model contact equates to the name of the contact.

Any assistance would be appreciated and apologies in advance if I have 
overlooked the obvious!

-- 
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/344565d3-0144-4069-b1db-6fa4003bd1a5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Custom Model Manager

2017-05-25 Thread 'dtdave' via Django users
I apologise if this is a simple question but I am still somewhat new to 
Dajngo.
I have the following models:

Jobs Model
Candidates Model
Applications Model

The jobs model has a manager on it as follows:
class ExpiredManager(models.Manager):
def get_queryset(self):
return super(ExpiredManager, self).get_queryset() \
 .filter(expiry_date__gt=datetime.now()).order_by('start_date')

And to make sure only unexpired items are listed on the web page my 
managers are listed as follows:
objects = ExpiredManager()
with_expired_objects = models.Manager()

Within my admin I have the following:
def get_queryset(self, request):
"""To return all jobs in admin including those that are expired"""
qs = self.model.with_expired_objects.get_queryset()
ordering = self.get_ordering(request)
if ordering:
qs = qs.order_by(*ordering)
return qs
At this stage evrything works exactly as I want it to with all jobs being 
shown in the admin and only unexpired jobs on the web page.

My candidates model has the following field:
jobs = models.ManyToManyField('jobs.Job', 
through="applications.Application")

My application model has fields for candidate and jobs.
My problem is that once the job expires it is being dropped from both the 
candidates and the applications as obviously the expired items manager is 
the default.
Any help on how to correct this would be appreciated.
Many thanks


-- 
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/a9349301-03db-4793-856b-b62836854de9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Link to urls containing slug

2017-01-31 Thread 'dtdave' via Django users
 

Within my model I have the following that links through to a detail page.

def get_absolute_url(self):



kwargs = {

  'job_id': self.job_id,

  'slug': self.slug,

   }

return reverse('job_detail', kwargs=kwargs)


Everything works fine with this.


Within my urls.py I have the following:

url(r'^$', views.JobListView.as_view(), name='job_list'),

url(r'^(?P[-\w]*)/(?P[-\w]*)/$', views.JobDetail.as_view(), 
name='job_detail'),

url(r'^(?P[-\w]*)/(?P[-\w]*)/job_application/$', 
views.job_application, name=‘job_application'),


Then within my views.py the following:

def job_application(request, job_id, slug):

# Retrieve job by id

job = get_object_or_404(Job, job_id=job_id)

“””Other code here


However, I am having problems linking to this from my template in my detail 
page.

What structure should I be using to link to the job application from the 
job detail page?


I can access the url by going to 

http://localhost:8000/jobs/1/name-of-job/job_application/


Any advice would be appreciated

-- 
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/0e6db077-52a8-4f23-862c-888ae0995e91%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Template Data

2016-11-18 Thread 'dtdave' via Django users
As still learning django I have a simple issue.

I have the following models:


class Contactnumber(TimeStampedModel):
phone_number = models.CharField(max_length=100, unique=True)
contact = models.ForeignKey(‘contacts.Contact')



class Contact(TimeStampedModel):
contact = models.CharField(max_length=100, db_index=True,
   verbose_name='Contact Name')
practice = models.ManyToManyField(‘practice.Practice’,
  related_name=“contacts",)



class Practice(TimeStampedModel):
practice = models.CharField(max_length=150, db_index=True,
verbose_name='Practice Name',
help_text="include location for 
multi-branch”)



I have a template including data tables in which I want to show the 
following:
Practice, Contact, Contact Phone 

The following gives me the contact for the practice:
{% for contact in practice.contacts.all %}
   {{ contact }}
   {% endfor %}

My question is how do  include the contact phone number as I seem a bit 
lost.
Any help would be appreciated. Apologies if this is a simple question!

-- 
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/0d8490a2-db29-435a-9477-e26dfa03c560%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Filters in Search

2016-10-20 Thread 'dtdave' via Django users
I have an issue that I have got myself into a mess trying to solve, so any 
help would be appreciated.

I have implemented a simple search solution that works fine and this is my 
view:

from django.shortcuts import render
from django.views.generic import ListView
from jobs.models import Job
from django.db.models import Q
from .filters import JobFilter


class JobListView(ListView):
model = Job
paginate_by = 10
template_name = 'jobs/job_list.html'

def get_queryset(self):
queryset = Job.objects.all()
q = self.request.GET.get("q")
if q:
queryset = queryset.filter(
Q(title__icontains=q) |
Q(category__category__icontains=q) |
Q(description__icontains=q)
).distinct()
self.sort_by = self.request.GET.get('sort_by', 'start_date')
return queryset.order_by(self.sort_by)

def get_context_data(self,  **kwargs):
context = super(JobListView, self).get_context_data(**kwargs)
context['title'] = "Job List"
context['sort_by'] = self.sort_by
context['object_name'] = "job_list"
return context

Everything thing works fine with this. However what I would like to do is 
to allow a person to filter on certain criteria within this page. I have 
created a separate view using django-filters which achieves this but would 
like to combine this. Any suggestions?
Thanks in advance. 

-- 
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/3da8cefb-7014-48f9-b323-e5e0745ce6c8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Postcode Search

2016-08-23 Thread 'dtdave' via Django users
I am looking to add the facility to "find my nearest" by postcode to my 
django app.

Does anyone have any recommendations for this facility?

Many thanks in advance.

-- 
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/66586c55-0f98-4232-8b06-4bb1e0045b43%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Reverse URL django-admin

2016-07-25 Thread 'dtdave' via Django users
I apologise in advance for the length of my post but I have included all 
the detail I can.

I have the following structure for an app. The list view template uses 
Bootstrap DataTables. My question is how to amend the urls to return the 
change url in django-admin.


models.py

def get_absolute_url(self):
return reverse('contact_detail', kwargs={"id": self.id})

urls.py


from django.conf.urls import url
from .views import (
contacts_list,
contacts_detail,
)


urlpatterns = [
url(r'^$', contacts_list, name='contact_list'),
url(r'^(?P\d+)/$', contacts_detail, name='contact_detail'),
]


views.py
from django.contrib.auth.decorators import user_passes_test
from django.shortcuts import render, get_object_or_404
from .models import Contact


@user_passes_test(lambda u: u.is_staff)
def contacts_list(request):
c = {}
contacts = Contact.objects.all()
c['contacts'] = contacts
return render(request, 'contacts/contacts_list.html', c)


def contacts_detail(request, id=None):
instance = get_object_or_404(Contact, id=id)
context = {
"title": "Contact Details",
"instance": instance,
}
return render(request, "contacts/contacts_detail.html", context)

contact_list.html
{{ contact.id }}

Any advice would be appreciated.

-- 
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/6c37dbdb-bfcc-4555-8112-abd849c78055%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Generic Foreign Key

2016-07-21 Thread 'dtdave' via Django users
I have two models notes and counties which are used across multiple models. 
At the moment the realtionship is done using a foreign key.

I am getting conflicting advice on whether to use a Generic Foreign Key. 
Could someone please enlighen me as to the best practice?

Many thanks in advance

-- 
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/37577063-87bf-4460-a6fb-7a17d74dc79c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.