Re: Login & Register

2022-02-26 Thread Clive Bruton

Use django-allauth package.


On 26 Feb 2022, at 15:09, Ankit Chaurasia wrote:

Hey, I am new in Djnaog and I want to make Login and Register Page  
with Email Verification.

Can anone share the code ?
and please gide me for the same.


--
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/C8B0DB95-4812-421B-9355-5FB3E9CC6DDB%40indx.co.uk.


Re: How to create dynamic models in django??

2022-02-28 Thread Clive Bruton



On 27 Feb 2022, at 17:54, Steve Smith wrote:

...the documentation on Formsets is scarce in my opinion and to get  
them to work is a lot of trial and error...


To massively simplify formsets try django-extra-views


-- Clive

--
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/5F1D5ACB-C5D8-460A-B471-D4B537A010F6%40indx.co.uk.


Re: How to create dynamic models in django??

2022-02-28 Thread Clive Bruton



On 28 Feb 2022, at 16:24, Prashanth Patelc wrote:


Any example?


Just read the django-extra-views documentation. Essentially a formset  
can be as simple to use as any of the built-in class-based views, eg:


from extra_views import InlineFormSetView

class EditContactAddresses(InlineFormSetView):
model = Contact
inline_model = Address
template_name = …


https://django-extra-views.readthedocs.io/en/latest/pages/formset- 
views.html#inlineformsetview



-- Clive

--
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/ACAAA816-D3DF-4732-9A45-8DFABABA0DEA%40indx.co.uk.


Re: Reusable django templates

2022-03-12 Thread Clive Bruton



On 12 Mar 2022, at 17:43, Heman Okumbo wrote:

How comes I'm not able to modify my templates after extending from  
a base template.eg can't add extra contents,the template only  
display contents of the inherited template.


Some code might help. It's not really clear to me what you are asking.

But at a guess, you can use the {% include … %} template function to  
extend templates.



-- Clive

--
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/2B3DC48B-D567-45A9-B182-66D13D81B4AF%40indx.co.uk.


Re: OperationalError at /admin/login database or disk is full

2022-05-27 Thread Clive Bruton



On 27 May 2022, at 22:37, Andrew Rea wrote:


OperationalError at /admin/login/
database or disk is full

Is this because my SQLite database is full from other projects? Or  
possibly because I have too many virtual envs from those same other  
projects? Or is it due to my personal computer's disk being too full?


I wouldn't bet on it, but I suspect that you do not have the correct  
permissions to write to the database. Because your HD really isn't  
full, is it?



-- Clive

--
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/CE3C33E3-7796-4ED5-92E5-190DDEBDE91E%40indx.co.uk.


Re: dynamic formular

2022-11-12 Thread Clive Bruton

Try django-extra-views

https://github.com/AndrewIngram/django-extra-views

Hugely simplifies formsets


On 10 Nov 2022, at 11:14, Arnold Falanga wrote:

Hello can anyone help me to design a dynamic form with Django the  
idea is to have two parts in this form. a link to add the lines


--
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/f9c74264-7cc0-448d-bcee-9110f7a91292n% 
40googlegroups.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/1F81F7CA-604F-4EF1-A707-B790B8A3B09B%40indx.co.uk.


Re: Single Sign On in Django

2022-11-16 Thread Clive Bruton

You can use django-allauth:

https://github.com/pennersr/django-allauth

On 10 Nov 2022, at 09:59, venkat Bukka wrote:


Hello all,
 Could anyone please let me know how we can implement SSO in the  
django...for authenticating multiple apps in a base application.


--
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/cc932efa-f41d-458d-901c-844e32bb1b5dn% 
40googlegroups.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/47C61FB0-FE30-4119-B4BD-934B366691F5%40indx.co.uk.


Re: Quiz app

2022-11-16 Thread Clive Bruton

Questions.objects.all().order_by('?')[:5]

ie get all the rows from the Questions table, in a random order, then  
show me the first five.


https://docs.djangoproject.com/en/dev/topics/db/queries/#limiting- 
querysets



-- Clive

On 16 Nov 2022, at 01:14, Lakshyaraj Dash wrote:


Hello everyone,
I'm on my way to create a quiz app. I want that a loggedin user  
should get 5 questions randomly when he/she is visiting everytime.

Eg:
On first visit
Q1. Who's the CEO of Facebook ?

On second visit
Q2. Who's the CEO of Google ?

Thanks and regards
Lakshyaraj Dash


--
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/CAF7qQgAAJinHYUKhY_M- 
Z0Y1ecrcHcWTyNHuHkSLdyV7QsFSqw%40mail.gmail.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/A99E62B4-627D-459F-B5A9-9927AF6AC9BB%40indx.co.uk.


Re: Need to Replace django default I'd with UUID field

2022-12-08 Thread Clive Bruton
It's more or less the same problem, use a new field to insert your  
new foreign keys (UUIDs), looking them up via your old foreign keys  
to get the new UUID values. Or, as the other Jason suggests, if you  
can, just use the UUIDs for external access.



-- Clive

On 22 Nov 2022, at 19:02, Rajesh Kumar wrote:


Hi Jason,
Thanks for a quick reply.

I got your point, but I am worry about my existing data/records  
which is already associated with id , which is default one.


On Wed, 23 Nov, 2022, 12:29 am Jason Turner,  
 wrote:
I would just add another column that holds the UUID value instead  
of changing the default ID.


On Tue, Nov 22, 2022, 12:55 PM Rajesh Kumar   
wrote:

Hi everyone!
Hope everyone is doing well...

Actually I have 100+ existing data in my database with default I'd  
field of django

Now I need to replace that default I'd to UUID.

How I can do  this without loosing any records of my database.

If anyone can give me suggestions that would be great.

Thanks
Rajesh Kumar

--
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/CAKNDe%3D%3DEa0ZagzpZ-Y_bXKrCi3ZHdG_PNr5% 
3DgxeJCTbKdM_tdA%40mail.gmail.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/CADoyC17Ar%2B5aHx2GHCdqTuHJagbJx6% 
3DFzj9zHP19-4-E1j6Pew%40mail.gmail.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/CAKNDe%3Dks0Gc%2BR8Hs6u%3DmhtQv3PjwyxaRqF2% 
3D7pwyP1NF34t5bQ%40mail.gmail.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/0DC12C1C-84CA-4102-8B05-8BA2329D3ED0%40indx.co.uk.


Re: join on plain integerfield

2022-12-08 Thread Clive Bruton

Try Django Relativity:

https://pypi.org/project/django-relativity/


-- Clive

On 21 Nov 2022, at 10:11, Marek Rouchal wrote:

Any suggestion how I can model such an integerfield, so that I can  
do joins on it using the Django ORM queryset syntax?




--
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/847DD166-E3C3-42D1-A10A-CDF0F19B7D75%40indx.co.uk.


Re: How to access the value of a field that failed validation

2023-01-15 Thread Clive Bruton

If you print:

   dir(form_instance)

You'll get the methods available to the form. From memory, amongst  
these you will find "data" and "initial", I think that "data"  
contains the information submitted in the form action. So, to show that:


   print(form.data)


-- Clive

On 2 Jan 2023, at 00:12, Noel Duffy wrote:

I'm new to Django, though not to programming. I'm using Django  
4.1.4 on AlmaLinux 9.


My question is this. Is it possible to access a ModelForm field's  
value if that form field failed validation?


I'm writing a small ticketing system for a helpdesk to handle spam  
reports. Users submit spam messages which the system will then  
process. I'm using a ModelForm, and the database schema specifies  
that the spam message is unique. That is, each spam message can be  
reported only once, so there's just one ticket but possibly many  
different actions taken depending on what's in the spam.


This is the model:

class AbuseReport(models.Model):
report_date = models.DateTimeField(auto_now_add=True)
report_subject = models.CharField(max_length=255)
report_msgid = models.CharField(max_length=255, unique = True)
report_spam_text = models.TextField(unique = True)
def __str__(self):
return report_subject

class Meta:
ordering = ['-report_date']

Now, the problem is that a spam message will fail form validation  
in the form.is_valid call if the spam message fails the "unique"  
constraint. Why is this a problem? Because I want to get my hands  
on the spam message if it's already in the DB so that instead of  
just re-showing my form with an error message saying the spam  
already exists, I want to redirect to the existing ticket. But so  
far I've not been able to figure out how to do this, and when I  
dump the contents of the form in debugging, the spam message just  
isn't there.


I should add that the ModelForm only creates a field for the  
report_spam_text field. I.e,


class AbuseReportForm(ModelForm):
def __init__(self, *args, **kwargs):
super(ModelForm, self).__init__(*args, **kwargs)

def clean(self):
[...]

class Meta:
model = AbuseReport
fields = ['report_spam_text']
widgets = {'report_spam_text':
   Textarea(attrs={
   'rows': 20,
   'class':'textarea',
   'placeholder':'Paste spam with full headers  
here..'

   }),}


This is what my view looks like (stripped down for simplicity):

def spamsubmit(request):
# if this is a POST request we need to process the form data
if request.method == 'POST':
# create a form instance and populate it with data from the  
request:

form = AbuseReportForm(request.POST)
# check whether it's valid:
if form.is_valid():
# process the data in form.cleaned_data as required
[.]
else:
## show the form again with errors displayed
## if spam already exists this is what gets run.
return render(request, 'abuse/spam_form.html', 
{'form':form})


As I understand it, fields aren't bound to data until is_valid is  
called, and if is_valid fails then only fields that didn't fail  
validity go into cleaned_data. But it seems everything else is  
lost. But I'm not 100% sure about this and this is why I'm asking.




--
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/tot7hm%2412qg%241%40ciao.gmane.io.




--
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/54B3AE49-5604-439D-94A7-96E6DE7B0387%40indx.co.uk.


Re: How to fetch 10000 above record within second in django?

2023-01-16 Thread Clive Bruton



On 17 Jan 2023, at 05:01, Prashanth Patelc wrote:

I written query it's taking more time like 38 seconds, how to to  
fetch the lac of records within seconds any example in django using  
orm or MySQL query ?


Are you saying that you have a raw SQL query, or you are using a  
Django query?


My experience is that the biggest lag in database retrieval is the  
amount of data retrieved, so if you can reduce the number of fields  
returned, that would be a good start.


If you are using a Django query, and it has related elements, then  
the biggest boost you can give is using "select_related" and  
"prefetch_related".



-- Clive

--
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/9EF46118-6870-46AD-BF58-12AEC8C6A518%40indx.co.uk.


Re: How to fetch 10000 above record within second in django?

2023-01-17 Thread Clive Bruton
The easiest way to debug this is to install django_debug_toolbar and  
look at the sql queries to see where the hold-up is.


As previously, restrict the number of fields returned using "values"  
and/or use "select_related" or "prefetch_related" to get related data  
in one or two queries, rather than having Django getting that data on  
(potentially) multiple queries per record.



-- Clive

On 17 Jan 2023, at 07:43, Prashanth Patelc wrote:

I'm using orm query fetching all data and showing into html  
templates , it's taking more time for get the data ,


On Tue, Jan 17, 2023, 12:40 PM Clive Bruton  wrote:

On 17 Jan 2023, at 05:01, Prashanth Patelc wrote:

> I written query it's taking more time like 38 seconds, how to to
> fetch the lac of records within seconds any example in django using
> orm or MySQL query ?

Are you saying that you have a raw SQL query, or you are using a
Django query?

My experience is that the biggest lag in database retrieval is the
amount of data retrieved, so if you can reduce the number of fields
returned, that would be a good start.

If you are using a Django query, and it has related elements, then
the biggest boost you can give is using "select_related" and
"prefetch_related".


-- Clive

--
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/9EF46118-6870-46AD-BF58-12AEC8C6A518% 
40indx.co.uk.


--
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/CAMCU6CrAKQL6qA6hWHPDFbfpCT1R9v5%2BY_Qi-HOkPf% 
3DOXYt2yA%40mail.gmail.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/52330EF7-BBD9-44E6-94E3-C0A733F4EF36%40indx.co.uk.


Re: How to fetch 10000 above record within second in django?

2023-01-17 Thread Clive Bruton



On 17 Jan 2023, at 12:06, Ayanfeoluwa Koyinsola wrote:

You might now have to display all the data at once, see if you can  
use paginisation to reduce the numbers of queries


I think this will only help if there are related lookups.


-- Clive

--
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/3ADD9645-859E-4452-9460-0917C367669B%40indx.co.uk.


Re: WHAT OTHER REAL TIME MAP CAN I USE IN MY PROJECT ASIDE GOOGLE MAP?

2023-03-25 Thread Clive Bruton

Here maps:

https://www.here.com

https://heremaps.github.io/


-- Clive

--
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/1F083D04-1CC7-4C84-AB45-BD82AD1521AF%40indx.co.uk.


Re: CSS with Django forms

2020-05-13 Thread Clive Bruton



On 12 May 2020, at 22:41, Anubhav Madhav wrote:


Is there any way to display the forms with my HTML CSS files.


Use {% include %} (https://docs.djangoproject.com/en/3.0/ref/ 
templates/builtins/#include) in your HTML template files for an  
embedded style sheet, or just use a link in the head of your template  
to serve the .css from the "static" folder (or other remote server  
location).



-- Clive

--
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/33DABBFA-7A36-42B0-9B9B-05C29ADEA7C9%40indx.co.uk.


Viewing available functions and variables

2020-05-13 Thread Clive Bruton
I am using django-allauth for a user registration/log-in system. I  
have this working, however, as a general question, I would like to  
understand how one can view the functions/variables available on a  
given template.


For example I see that in some templates these are included:

{% user_display confirmation.email_address.user as user_display %}

{{ emailaddress.email }}

But I cannot, for example, access these in templates used for sending  
email.


Hope that is clear.


-- Clive

--
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/309D6173-2B9B-4A48-B5FD-2104BA33C1E2%40indx.co.uk.


Re: CSS with Django forms

2020-05-15 Thread Clive Bruton
You can use bootsrap4, or look at the output from the forms and set  
up your CSS around that.



-- Clive

On 14 May 2020, at 19:40, Anubhav Madhav wrote:

Thankyou Clive!! I know I can use CSS like that, but if I do that  
the problem I'll face is that the 'form' or the 'input' tags or  
'submit' button, which are rendered using django forms, cannot be  
modified using CSS in this way. Is there any other way to fix it?


On Wednesday, 13 May 2020 18:58:08 UTC+5:30, Clive Bruton wrote:
On 12 May 2020, at 22:41, Anubhav Madhav wrote:

> Is there any way to display the forms with my HTML CSS files.

Use {% include %} (https://docs.djangoproject.com/en/3.0/ref/
templates/builtins/#include) in your HTML template files for an
embedded style sheet, or just use a link in the head of your template
to serve the .css from the "static" folder (or other remote server
location).


-- Clive 


--
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/d9650e11-31a1-44ff-a4c4-2a59e7ac27cf% 
40googlegroups.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/60071141-DB7F-4D3B-8529-148FDE2A6C57%40indx.co.uk.


Re: Bootstrap drop down menu not clickable.

2020-05-16 Thread Clive Bruton



On 16 May 2020, at 15:03, sunday honesty wrote:

I did that and got a TemplateSyntaxError stating that bootstrap4 is  
not a registered tag library


Did you put it in your installed_apps?


-- Clive

--
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/AF951EBC-2228-4CB5-92CA-F7207A31DE0B%40indx.co.uk.


Re: Bootstrap drop down menu not clickable.

2020-05-16 Thread Clive Bruton



On 16 May 2020, at 15:43, sunday honesty wrote:

I included it to installed app and got an error message on the  
console. "Module not found, no module named bootstrap 4"


"bootstrap4"


-- Clive

--
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/7552335C-16B0-4114-B1F3-5A3F8C1CD02A%40indx.co.uk.


Re: Categories and shoe Subcategories according to the parent category.

2020-05-19 Thread Clive Bruton

There are django modules for hierarchical navigation

https://djangopackages.org/grids/g/navigation/


-- Clive


On 19 May 2020, at 23:20, saqlain abbas wrote:


Please tell me if anyone knows about this.

On Mon, May 18, 2020 at 4:50 PM saqlain abbas  
 wrote:

Hi, if i add Categories , for example
1)accessories
2)sports
3)books
Subcategories:
accessories is the parent category
child categories are
watches
jewlry
caps
how can i show if  user selects the parent category accessories  
then the subcategories show according to parent categories like  
subcategories are watches jewlry etc


--
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/1530c511-072f-44ee-83fa-3555bd090a89% 
40googlegroups.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/CAP6Ddn3zr%2BsfaL6DGMHb- 
xsLpE1zKcToKjKEqoPU6PCgGqjh1w%40mail.gmail.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/3E93BF89-D7B4-4715-A666-30EAE076418B%40indx.co.uk.


Date comparison as a filter

2020-06-07 Thread Clive Bruton
I would like to add a date comparison filter to a lookup, to find  
items in a database table that have not yet expired. I tried:


.filter(expires>=datetime.today()) \

But this does not appear to have any effect.

"expires" is a column in the table of datetime type, that looks like  
this:


"2020-07-08 01:17:27.952874"

Or do I have to format "datetime.today()" to match the format  
displayed in the database table?


Thanks


-- Clive

--
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/D59D05A5-02D8-42BD-A410-3ECDE22A9974%40indx.co.uk.


Re: Python 3.8 Installed, yet Django 1.11 is Automatically Being Installed on Mac

2020-06-09 Thread Clive Bruton

You have to use the correct python install:

python3 -m pip install django

You can test your versions and locations:

which python3
which python

python3 -V
python -V

When you are running the development server:

python3 manage.py runserver

You can have multiple python versions installed, you just need to  
understand which one you are addressing/using.



-- Clive

On 9 Jun 2020, at 03:37, arhoon io wrote:


Hello,

I have installed and successfully confirmed that Python 3.8 works  
on my Mac.  However, when I pip installed the latest version of  
Django, it automatically installed Django 1.11 even though I have  
Python 3.8.


When typing in "python" into terminal, it runs Python 2.7 - so that  
is my guess.


If that is true, how do I get the actual latest version of Django  
(3.0)?


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 view this discussion on the web visit https://groups.google.com/ 
d/msgid/django-users/d02c23bd-0c04-47c1-8602-63c74e35e144o% 
40googlegroups.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/842AFD7C-4F75-4F68-84AC-B86E4C98ED0F%40indx.co.uk.


Compare logged-in user against record owner in filter

2020-06-10 Thread Clive Bruton
I am trying to create a queryset that filters against the logged-in  
user's id and the user_id in the record, ie so that only the relevant  
user can see the record.


Without the filter, when I display the page I can capture elements in  
the template that would allow this comparison, ie:


object.user.id # the record owner
user.id # the logged-in user's id
object.user # the record owner's user name
user # the logged-in user’s user name

So, in models.py I made a new query manager:

class EditManager(models.Manager):
def get_queryset(self):
return super(EditManager, self).get_queryset().filter(
user.id==object.user.id,
expires__gte=datetime.now(timezone.utc),
is_active=True)

Then the debug gives the following error:

Exception Value:name 'user' is not defined

Even if I try fields that are obviously in the table, just to get a  
nonsensical filter, I get similar errors, eg "id==user_id".


I have tried variations on the user id comparison, but have not got  
any further.


Or, am I going about this completely the wrong way?

Any help greatly appreciated.


-- Clive

--
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/3F70FF33-445A-4EB4-A582-6C20268B0355%40indx.co.uk.


Updating a date field

2020-06-13 Thread Clive Bruton
I am trying to update an existing date field, however when I do that  
I get the following exception:


Exception Type: TypeError
Exception Value: expected string or bytes-like object

The query looks like this:

queryset = Item.edit.filter(**kwargs).update 
(expires=set_expires,is_active=True)


and set_expires looks like this:

def set_expires():
return datetime.now(timezone.utc) + timedelta(days=30)

I am using "set_expires" in the model for "Item", to set the initial  
value, without issue. Do I have to convert to a string when doing an  
update?


Thanks


-- Clive

--
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/8B6B6771-0E9C-4E4A-A696-18CF9B7ED355%40indx.co.uk.


Re: Updating a date field

2020-06-14 Thread Clive Bruton

Apparently the magic is:

queryset = Item.edit.filter(**kwargs).update(expires=set_expires 
(),is_active=True)



-- Clive

On 14 Jun 2020, at 03:24, Clive Bruton wrote:

I am trying to update an existing date field, however when I do  
that I get the following exception:


Exception Type: TypeError
Exception Value: expected string or bytes-like object

The query looks like this:

queryset = Item.edit.filter(**kwargs).update 
(expires=set_expires,is_active=True)


and set_expires looks like this:

def set_expires():
return datetime.now(timezone.utc) + timedelta(days=30)

I am using "set_expires" in the model for "Item", to set the  
initial value, without issue. Do I have to convert to a string when  
doing an update?


Thanks


-- Clive

--
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/8B6B6771-0E9C-4E4A-A696-18CF9B7ED355% 
40indx.co.uk.




--
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/29D80E69-FDDF-4736-9AA0-2E4DBB9C972E%40indx.co.uk.


Re: Custom Primary Key

2020-06-23 Thread Clive Bruton



On 23 Jun 2020, at 23:32, Oleg Kishenkov wrote:

Hello Soumen, you should use a CharField with the primary_key=True  
attribute for your model. This way no no automatic primary key  
field is generated, your field will be implicitly unique and non- 
null though. Only one primary key is allowed in a model.


class Foo(models.Model)
id = models.CharField(max_length=15, primary_key=True)


Just to clarify this, are you indicating that when you create the  
record you generate a unique custom key yourself and insert this?



-- Clive

--
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/E9317D0D-0A25-48CE-9396-5FB181075045%40indx.co.uk.


Form theory - locking a field

2020-06-24 Thread Clive Bruton
I have a form in which, after filing, I would like one field to be  
locked for editing, the forms.py looks like this:


**

class ProfileForm(forms.ModelForm):
status = forms.ChoiceField(choices=Profile.status_choices,  
widget=forms.RadioSelect)


class Meta:
model = Profile
fields = (
'status', 'phone', 'display_phone', 'display_address',  
'display_email', 'display_loginoverride'

)
widgets = {
'phone': PhoneWidget
}

**


While the user will be able to come back and change the other  
information on the form, I want to be able to lock the "status"  
field, so that it just shows the input they selected, not the radio  
buttons and is no longer editable by the user.


Is there a way to do this in forms.py, or would I have to construct  
the logic in a template (or perhaps some other way)?


Thanks


-- Clive

--
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/7A4BCC9C-172C-4511-A422-6E832A72E11D%40indx.co.uk.


Re: Custom Primary Key

2020-06-24 Thread Clive Bruton



On 24 Jun 2020, at 06:24, Soumen Khatua wrote:

Yes, at the time of add a new record in model, automatically I want  
to create a custom ID and insert it into model


There is a post about this at Stack Overflow:

https://stackoverflow.com/questions/52070462/django-generate-custom-id


-- Clive

--
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/7722F772-8C9D-4E4C-8B86-45AEF488036A%40indx.co.uk.


Re: Form theory - locking a field

2020-06-24 Thread Clive Bruton



On 24 Jun 2020, at 23:03, Chetan Ganji wrote:


Try this one
https://docs.djangoproject.com/en/3.0/ref/forms/fields/#disabled


Ok, well that's a little help, because I can disable the input:

status = forms.ChoiceField(choices=Profile.status_choices,  
widget=forms.RadioSelect(attrs={'disabled': True}))


And I can put a "useless" if statement around it to get different  
outputs:


if 1 == 1 :
status = forms.ChoiceField(choices=Profile.status_choices,  
widget=forms.RadioSelect(attrs={'disabled': True}))

else :
status = forms.ChoiceField(choices=Profile.status_choices,  
widget=forms.RadioSelect(attrs={}))


But, I can't work out how to get a meaningful if comparison, like:

if Profile.status == 'personal' :
status = forms.ChoiceField(choices=Profile.status_choices,  
widget=forms.RadioSelect(attrs={'disabled': True}))

else :
status = forms.ChoiceField(choices=Profile.status_choices,  
widget=forms.RadioSelect(attrs={}))


Any string I put in 'personal' always returns false, so I can switch  
the output with "==" or "!=", but I can't assess the output in  
reference to what I expect to be in the database fields. Django  
accepts "Profile.status" as a relevant property, so I am a bit lost  
as to how to continue, or debug this. If I try "print(locals()) or  
print(Profile.status) I get no output in the terminal.



-- Clive

--
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/940FE834-1B08-4542-934C-808668E99B35%40indx.co.uk.


Re: CSS file not Loading

2020-06-28 Thread Clive Bruton
If you are testing the site with manage.py runserver, then you have  
to make sure debug is on. And you have to ensure the app knows where  
the static directories are.



-- Clive

On 28 Jun 2020, at 12:21, Suny wrote:


Do I need to add STATICFILES_DIRS in settings.py file

TREE STRUCTURE for reference :
.
├── db.sqlite3
├── Fotografie
│   ├── asgi.py
│   ├── __init__.py
│   ├── __pycache__
│   │   ├── __init__.cpython-38.pyc
│   │   ├── settings.cpython-38.pyc
│   │   ├── urls.cpython-38.pyc
│   │   └── wsgi.cpython-38.pyc
│   ├── settings.py
│   ├── urls.py
│   └── wsgi.py
├── Home
│   ├── admin.py
│   ├── apps.py
│   ├── __init__.py
│   ├── migrations
│   │   ├── 0001_initial.py
│   │   ├── __init__.py
│   │   └── __pycache__
│   │   ├── 0001_initial.cpython-38.pyc
│   │   └── __init__.cpython-38.pyc
│   ├── models.py
│   ├── __pycache__
│   │   ├── admin.cpython-38.pyc
│   │   ├── apps.cpython-38.pyc
│   │   ├── __init__.cpython-38.pyc
│   │   ├── models.cpython-38.pyc
│   │   ├── urls.cpython-38.pyc
│   │   └── views.cpython-38.pyc
│   ├── static
│   │   └── Home
│   │   └── main.css
│   ├── templates
│   │   └── Home
│   │   ├── about.html
│   │   ├── base.html
│   │   ├── contact.html
│   │   └── home.html
│   ├── tests.py
│   ├── urls.py
│   └── views.py
├── manage.py
└── Users
├── admin.py
├── apps.py
├── __init__.py
├── migrations
│   ├── __init__.py
│   └── __pycache__
│   └── __init__.cpython-38.pyc
├── models.py
├── __pycache__
│   ├── admin.cpython-38.pyc
│   ├── apps.cpython-38.pyc
│   ├── __init__.cpython-38.pyc
│   ├── models.cpython-38.pyc
│   ├── urls.cpython-38.pyc
│   └── views.cpython-38.pyc
├── templates
│   └── Users
│   └── register.html
├── tests.py
├── urls.py
└── views.py


base.html file

{% load static %}







https://maxcdn.bootstrapcdn.com/ 
bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384- 
Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm"  
crossorigin="anonymous">

https://fonts.googleapis.com/css? 
family=Sofia">
https://fonts.googleapis.com/css? 
family=Annie Use Your Telescope">
rel='stylesheet'>

Fotografie







css file with main.css name

body {
  background-color: #181818;  /*background of page*/
  color: #FF;   /*color of text*/
  margin-top: 1000rem;/*margin from top*/
}

h1, h2, h3, h4, h5, h6 {
  color: #FF;
  text-transform: uppercase;
}

ul {
  margin: 0;
}


setting.py file
"""
Django settings for Fotografie project.

Generated by 'django-admin startproject' using Django 3.0.7.

For more information on this file, see
https://docs.djangoproject.com/en/3.0/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.0/ref/settings/
"""

import os

# Build paths inside the project like this: os.path.join 
(BASE_DIR, ...)

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.0/howto/deployment/ 
checklist/


# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = ')!e)l*b%z(ywdugroidcrjq4a%&dt7ha2*^amf8s150ndy%+@i'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [  #list collector
'Home.apps.HomeConfig',
'Users.apps.UsersConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'Fotografie.urls'

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]

WSGI_APPLICATION = 'Fotografie.wsgi.application'


# Database
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}


# Password validation

Re: Primary keys using sequences

2020-07-01 Thread Clive Bruton



On 2 Jul 2020, at 00:06, Stats Student wrote:

Hi, I am using a Postgres database and have been populating the  
primary key from a sequence. Is there any way to define this  
behavior through Django's ORM? Thanks


I think you are basically asking how to create a custom key. This was  
discussed a few days ago, look for the thread "Custom Primary Key".



-- Clive

--
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/762F7935-2DA1-4334-B706-48675E8E5D2A%40indx.co.uk.


Trouble getting kwargs into filter

2020-07-05 Thread Clive Bruton

I am struggling with getting kwarg values into a queryset filter:

class UsersItemsView(ListView):
template_name = 'testapp/user_item_list.html'

def get_queryset(self, **kwargs):
print('kwargs-userlist')
print(kwargs)
#return Item.objects.filter(user__username='clive')
#return Item.objects.filter(user__id=2)
return Item.objects.filter(user__id=kwargs['userlist'])

def dispatch(self, *args, **kwargs):
print('kwargs-userlist')
print(kwargs['userlist'])
return super(UsersItemsView, self).dispatch(*args, **kwargs)


On dispatch, I can see the value for "kwargs['userlist']" printed in  
the terminal.


But, the queryset returns an error:

Exception Type: KeyError
Exception Value: 'userlist'

I understand this to mean that the key 'userlist' is not in kwargs,  
and this is confirmed if I "print(kwargs)" inside the get_queryset


If I use the hard-coded filters, commented-out above  
("user__username='clive'", "user__id=2"), I get the result (from the  
template) that I expect.


So, how do I get the "kwargs['userlist']" passed to the queryset?


Thanks


-- Clive

--
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/5BD32BE1-331F-4AE5-BB8A-2E769D728972%40indx.co.uk.


Re: Trouble getting kwargs into filter

2020-07-06 Thread Clive Bruton

Thank you.


On 6 Jul 2020, at 05:24, Stephen J. Butler wrote:


 def get_queryset(self):
 qs = super().get_queryset()
 return qs.filter(user__id=self.kwargs['userlist'])


--
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/06B8D1F3-83B7-4EB0-A44A-0916DF93321A%40indx.co.uk.


Adding an 'or' to filter

2020-07-06 Thread Clive Bruton

I am working into someone else's solution, with this code in forms.py:

***

class SearchForm(forms.Form):
area = forms.ModelChoiceField(label=_('Area'),  
queryset=Area.objects.all(), required=False)
group = forms.ModelChoiceField(label=_('Group'),  
queryset=Group.objects.all(), required=False)

q = forms.CharField(required=False, label=_('Query'),)

def filter_by(self):
# TODO search using more than one field
# TODO split query string and make seaprate search by words
filters = {}
if self.cleaned_data['group']:
filters['group'] = self.cleaned_data['group']

if self.cleaned_data['area']:
filters['area'] = self.cleaned_data['area']

filters['description__icontains'] = self.cleaned_data['q']

return filters

***

I understand that 'filters' is a dictionary.

However, what I would like to do is have the final input ('q') be an  
'or' search on two fields, ie:


filter(Q(description__icontains = self.cleaned_data['q']) | Q 
(title__icontains = self.cleaned_data['q'])]


Not sure how to implement that in this dictionary style.

Thanks


-- Clive

--
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/2525F534-DD0C-48E6-ABFC-D3D1FA29E09C%40indx.co.uk.


Re: transforming form input

2020-07-08 Thread Clive Bruton



On 7 Jul 2020, at 22:58, Kai Kobschätzki wrote:


I render one input field surname. And if the user writes one string in
the input field it should be saved to surname (so forename is  
None). If

the user writes two strings (separated through a white space) than the
first part should be saved to forename and the second one to surname
(and perhaps I want to make some string manipulation further).


This isn't a "safe" way of delineating forename/surname. It isn't  
that uncommon for people to have unhyphenated compound surnames, eg:


Bruce Smith Jones

To see the confusion this may cause:

https://en.wikipedia.org/wiki/Arthur_Conan_Doyle

It is better to ask for the forename input separately, or at least  
give the user the option to override your decision.



-- Clive

--
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/E644135A-7C74-4689-B3CB-6AA03224AC84%40indx.co.uk.


Django conditional field display on form

2020-10-15 Thread Clive Bruton
I am trying to make a simple form, that conditionally shows the  
"website" input field based on the value of another database field  
(that is not on the form) "status". For the sake of this process the  
"status" field is not editable by the user, just by the admin. Both  
fields are in the same table: "profile".


After working at this for a while I copped-out and just did the  
conditional hiding and showing on the template. But, I realise this  
is the unsophisticated method, and would like to improve it.


What I tried so far in forms.py:



class WebsiteForm(forms.ModelForm):
class Meta:
 model = Profile

 fields = ( 'e-mail', 'website', )

 if Profile.status == 'personal' :
 exclude = ('website',)

This method in forms.py works effectively, in that I can  
conditionally show and hide the field if I use test comparitors in  
the if statement like:


if 1 == 1:
or

if 1 != 1:
But, I cannot get an effective test using the field "Profile.status",  
the value in the field seems to be unavailable at the point the "if"  
test in forms.py is performed.


If I use "print(Profile.status)" I get the following output in the  
terminal: "user__profile__status__isnull", so I think this means that  
I am at least testing the correct field in the database. Although I  
am also noting that this output only shows at initialisation of  
"runserver", not when the form page is accessed.


One final point, the user is authenticated and editing their own record.

Any help very much appreciated.





-- Clive

--
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/99ABE658-5CF2-4EB3-8E96-6AD2D32CB34B%40indx.co.uk.


Re: Dynamic Logo

2020-10-18 Thread Clive Bruton



On 18 Oct 2020, at 12:53, Asaduzzaman Sohel wrote:

I am creating a django application. now I would like to create  
logo, site name & info which will be dynamic. I want to create  
Model for this , but problem is use create many logo, site name or  
info. but Use can create or edit only one logo, one site name. How  
can I do this?


There are probably endless ways to create dynamic/changing content  
and design/logos, you need to be a bit more specific about what you  
want to achieve.


The easiest way to create a changing site name is to put words in a  
table and randomly choose one or more.



-- Clive

--
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/C1213021-216E-470A-9A33-544465E298B6%40indx.co.uk.


Get datetime now, not at server initialisation

2020-10-27 Thread Clive Bruton
I have a function that uses the current date to set up a file path  
for uploaded images:




def upload_path():
dtnow = datetime.now(timezone.utc)
dtstr = '{:%Y/%m/%d/%H/%M/%S}'.format(dtnow)
print('dtstr: ')
print(dtstr)
dtstr = 'images/items/' + dtstr
return dtstr

class Image(models.Model):
item = models.ForeignKey(Item, on_delete=models.CASCADE)
#file = ImageField(_('image'), upload_to='images')
file = ImageField(_('image'), upload_to=upload_path())



The problem is that when the Image class calls 'upload_path' the  
datetime portion of this is always the runserver initialisation time,  
rather than the time when 'upload_path' is called/used.


How to fix this?

Thanks


-- Clive

--
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/AE06A649-0B34-46F2-9FD0-0386B2843D93%40indx.co.uk.


Re: Get datetime now, not at server initialisation

2020-10-28 Thread Clive Bruton
Thanks, that was very helpful. I had another pointer on this and  
found out that the easiest way to do this is just to change the  
```file``` line in the class to:


```
file = ImageField(_('image'), upload_to='images/items/%Y/%m/%d/% 
H/%M/%S')



There are a few things that I do not understand, however, after  
playing around with some code for a while.


If I just pass a string to ```file``` it understands that this is a  
partial path, and it has to stick ```filename``` on the end. eg:


```file = ImageField(_('image'), upload_to='images/items')```

Likewise with the version above with the date formatting.

This is also the case when I used my initial ```upload_path```  
function, calling it with ```upload_to=upload_path()``` – but this  
did not suit the task, because ```upload_path``` loaded at  
initialisation of the server.


So, given that ```upload_path``` returns a string, I don't understand  
why I also have to concatenate the ```filename```:


```
def upload_path(instance, filename):
dtnow = datetime.now(timezone.utc)
dtstr = '{:%Y/%m/%d}'.format(dtnow)
dtstr = 'images/items/' + dtstr + '/' + filename
return dtstr
```
In this case, if I do not concatenate ```filename``` then the  
uploaded file gets named with the last element of the date formatting  
and without a file extension, ie potentially like this:


```images/items/2020/10/28/20/59/55```

rather than:

```images/items/2020/10/28/20/59/55/image.jpg```

The other thing I don't understand is how ```instance``` and  
```filename``` are passed to the function ```upload_path```. I would  
expect to do something like:


```	file = ImageField(_('image'), upload_to=upload_path(instance,  
filename))```


But if I do that I get:

```NameError: name 'instance' is not defined```

Sorry for so many more questions!


-- Clive

On 28 Oct 2020, at 08:58, Carles Pina i Estany wrote:



Hi,

On Oct/27/2020, Clive Bruton wrote:

I have a function that uses the current date to set up a file path  
for

uploaded images:



def upload_path():


[...]


class Image(models.Model):
item = models.ForeignKey(Item, on_delete=models.CASCADE)
#file = ImageField(_('image'), upload_to='images')
file = ImageField(_('image'), upload_to=upload_path())




The problem is that when the Image class calls 'upload_path' the
datetime portion of this is always the runserver initialisation time,
rather than the time when 'upload_path' is called/used.

How to fix this?


For what I remeber (I use FileField usually but this is noto  
relevant I

hope) you should do:

def upload_path(instance, filename):
# you have access to the instance (object model Image in your  
case)

# and the filename that the user used to upload it
# and this is executed on the upload time
return your_new_file_name

In the model:
file = ImageField(_('image'), upload_to=upload_path)

note that upload_path is a callable: it gets called on the upload  
time.

In your code it was called on initialization time.

Some time ago I had a similar code that caused a bug: in a ListView  
the

"queryset = " is executed on startup time. For a dynamic one I should
have used get_queryset() method.

--
Carles Pina i Estany
https://carles.pina.cat

--
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/20201028085843.GA20091%40pina.cat.




--
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/2FBF21DA-2057-4302-BED8-629F9C835337%40indx.co.uk.


Re: Get datetime now, not at server initialisation

2020-11-01 Thread Clive Bruton



On 30 Oct 2020, at 11:00, Carles Pina i Estany wrote:


Let me know if it's not clear or if I explained something that you
didn't ask!


Thanks you very much for spending the time on this, to explain it to  
me - it was very helpful!



-- Clive

--
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/BBE7C073-E0A4-4927-8A7B-DA13861D40B4%40indx.co.uk.


Re: getting 404 page not found on part 3 of the tutorial

2020-11-11 Thread Clive Bruton



On 11 Nov 2020, at 23:37, George P. Olson wrote:


So when I go to this url: http://127.0.0.1:8000/polls/


Although the urlpatterns below shows "# ex: /polls/", the defined  
path has no path elements, so you just need:


http://127.0.0.1:8000/

I think.


urlpatterns = [
# ex: /polls/
path('', views.index, name='index'),...



-- Clive

--
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/83D6D705-ACA5-49C1-B421-2E4729414B71%40indx.co.uk.


Re: getting 404 page not found on part 3 of the tutorial

2020-11-11 Thread Clive Bruton
Sorry, I just checked my version of the tutorial, you load the  
manage.py through the directory "mysite", and "polls" is in a sub- 
directory. The way you showed the "/polls/urls.py" implied that was  
the only file, where in fact the root app/settings are at "/mysite/ 
settings.py" and urls at "/mysite/urls.py".


Because "/mysite/urls.py" has an include for "polls/urls.py" it  
implies the path "/polls".


It's a bit tricky to diagnose, because you are now saying it was  
working, but then you changed stuff. My directory setup looks like this:


/mysite/manage.py
...
/mysite/mysite/settings.py
...
/mysite/mysite/urls.py
...
/mysite/polls/settings.py
...
/mysite/polls/urls.py

I checked my polls.py, which looks like this:

*

from django.urls import path

from . import views

app_name = 'polls'

"""
urlpatterns = [
# ex: /polls/
path('', views.index, name='index'),
# ex: /polls/5/
path('/', views.detail, name='detail'),
# ex: /polls/5/results/
path('/results/', views.results, name='results'),
# ex: /polls/5/vote/
path('/vote/', views.vote, name='vote'),
]
"""

urlpatterns = [
path('', views.IndexView.as_view(), name='index'),
path('/', views.DetailView.as_view(), name='detail'),
path('/results/', views.ResultsView.as_view(),  
name='results'),

path('/vote/', views.vote, name='vote'),
]

***

I think I read recently that generic views like "IndexView" need a  
".as_view()" attached to the end to be recognised.



-- Clive


On 12 Nov 2020, at 04:35, George Olson wrote:


I don't quite follow your note there of just going to:
http://127.0.0.1:8000/
without the app name 'polls' following.

I believe you have to put the app name following that. It was  
working before with http://127.0.0.1:8000/polls/, but then I did  
something and tried to backtrack and the whole system got messed  
up. I tried to reset everything back to the original but it is  
still not working.


On Wednesday, November 11, 2020 at 7:47:58 PM UTC-6 Clive Bruton  
wrote:


On 11 Nov 2020, at 23:37, George P. Olson wrote:

> So when I go to this url: http://127.0.0.1:8000/polls/

Although the urlpatterns below shows "# ex: /polls/", the defined
path has no path elements, so you just need:

http://127.0.0.1:8000/

I think.

> urlpatterns = [
> # ex: /polls/
> path('', views.index, name='index'),...


-- Clive 



--
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/1feb0c4a-8919-4aff-abb1-e0110392c396n% 
40googlegroups.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/6B7CE16C-69CD-4291-AC32-A81D54023029%40indx.co.uk.


How to avoid select lists on formsets and ManyToMany?

2021-04-01 Thread Clive Bruton
I have a ManyToMany model set, that on the edit uses a formset to add/ 
edit rows. I have this working, but the unfortunate part of it is  
that the select that results from the ManyToMany relationship  
populates with 16,000 records.


What I would like to do is, once the records are added, just have the  
delete checkbox and show the 'description' field (uneditable) next to  
it), and, rather than add records through a huge select list, add the  
records by id.


To sketch it out, this is how it is:


<'Profile.directory-optin' checkbox>

<'Profile.directory-desc'>

<'Class.description' huge select>





<'Class.description' huge select>





<'Class.description' huge select>







<'Class.description' huge select>









And I'd rather it was something like:


<'Profile.directory-optin' checkbox>

<'Profile.directory-desc'>

 



 



 














The database tables look something like:


Profile  Join table   Class
===  ==   =

id   id   id
directory-optin  profile-id   description
directory-desc   class-id



Hope someone can help me out!


-- Clive

--
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/E30F44E6-07DA-4703-BAB1-BE295C72EF22%40indx.co.uk.


Re:

2021-04-02 Thread Clive Bruton
Find a project on github and suggest some easy fixes. I'm no django  
expert, but I've had patches accepted on at least three projects.


The last one I contributed to was updating the code from django 1.x  
to 3.x, so that it would run on more recent versions. This is quite  
easy to do, since the debug will give you the errors, and then you  
can just search for the solutions.



-- Clive

On 2 Apr 2021, at 11:10, Richard Dushime wrote:


dear developers i am requesting for help
i am  new  and i wanted to start contributing on a project  but i  
have failed on how to start i have seen one project ideas but i am  
not seeing a mentor contacts  please i need a help

thank you

--
You received this message because you are subscribed to the Google  
Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it,  
send an email to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/ 
d/msgid/django-users/CAJCm56Kf9mxV7jxErjFBspBaQKBDPoUPGQkWRjSmO3h% 
2Btmdw0w%40mail.gmail.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/2C87261E-2A29-471D-A347-213D8E4918F1%40indx.co.uk.


Re: bonjour tout le monde Je suis confronte a cette erreur depuis 2 jours....besoins d'aide svp

2023-11-26 Thread Clive Bruton
Sorry I can't reply in French. It simply means that a template is  
expected in your project/app folder at:


[project/app]/templates/registration/logout.html


-- Clive

On 26 Nov 2023, at 11:55, fabrice ayissi awono wrote:




--
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/916d7cbc-40b2-4cf8-83bb-7ed054a350ffn% 
40googlegroups.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/B07D5682-FEC1-4E44-BF8D-6B31BCA98185%40indx.co.uk.


Re: Custom User models

2023-11-27 Thread Clive Bruton
I am taking it that there is more than one "school"? If so, surely  
it's is just a many-to-many relationship.


On 27 Nov 2023, at 09:33, Okkert Joubert wrote:


Good morning all,

I made a custom user model for a school, it is currently working  
with djoser authentication, now what I want to add is for the  
school to add users, so my School model is a foreignkey in  
SchoolUser is this possible firstly and secondly can I add the  
djoser authentication to the SchoolUser model as well


--
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/2754d7b3-a54a-40d6-9cab-50c0a2dbb812n% 
40googlegroups.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/650A06A2-C854-4361-9BF3-5CCDF636F2D0%40indx.co.uk.


Re: Registration form in template

2024-03-19 Thread Clive Bruton
If you want to override what the form is showing, then you can build  
your own template and only include the elements that you wish to show.


Rather than use:

{{ form }}

use:

{{ form.field_name }}

or break it down further, like:

{{ form.field_name.html_name }}

etc

Consequently, depending on how much you wish to omit, you may need  
code the HTML tags and attributes.



On 18 Mar 2024, at 04:13, 'Simon Connah' via Django users wrote:

I have a register user template with a form which works well but I  
have a problem where there is lots of other text next to the form  
elements such as password length and what characters need to go in  
a password. Is their a reasonable way to hide that text or do I  
need to do it with JavaScript?


Thank you.

Simon.

--
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/ 
xepYvHchH7kpHYeaYe7ByePm8VQYSjgIEzyGjSKDhOcAOhbh7j1vLmwSgLEgC5kkq- 
wYMOHjPM7--mLSu9w22I_BT9A-sQjZgTxVi9RR8IM%3D%40protonmail.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/7A28A81D-A8D4-4075-AABB-C6599DE2AACB%40indx.co.uk.