Reverse function fails for a single app

2023-11-24 Thread Derek
Using Django 2.2 and Python 3.9

When I try to use reverse() for testing one of my apps, it fails. All the
others seem to work OK.

An example code snippet:

from django.test import TestCase

class TestCaseSimple(TestCase):

def setUp(self):
User.objects.create_superuser(
username='t...@example.com',
password='password',
)

def test_test(self):
self.login = self.client.login(username='t...@example.com',
password='password')
assert self.login is True
url = reverse('admin:appone_modelone_changelist')
print(url)  # passes
url = reverse('admin:apptwo_modeltwo_changelist')
print(url)  # fails

Part of error response:

E   django.urls.exceptions.NoReverseMatch: Reverse for
'apptwo_modeltwo_changelist' not found. 'apptwo_modeltwo_changelist' is not
a valid view function or pattern name.

/home/derek/miniconda3/envs/tp32/lib/python3.9/site-packages/django/urls/resolvers.py:677:
NoReverseMatch

During normal use, the app behaves fine and any other tests not requiring
reverse all work OK.

What could cause the URLs for this single app not to be found by the
resolver code?

-- 
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/CAF1Wu3PCBXhAxVgB7aLoYzNbCUXBWeSWyjLnBGX_2%3DWfqo7GEw%40mail.gmail.com.


Re: How to solve primary key error in django?

2023-01-09 Thread Derek
Also understand that using '0' for a primary key is NOT recommended by 
MySQL; look at:
https://dev.mysql.com/doc/refman/5.7/en/sql-mode.html#sqlmode_no_auto_value_on_zero
 

This has bitten me before when migrating data from other types of DBMS.

On Thursday, 5 January 2023 at 12:09:35 UTC+2 prashan...@gmail.com wrote:

> I'm using MySQL database in django when I am creating
>
> Id=models.AutoField(primary_key=True)
>
> It's showing below error.
>

-- 
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/0bb90f3f-e8cb-405d-969b-9b00a157862bn%40googlegroups.com.


Re: Fwd: Delivery Status Notification (Failure)

2022-09-18 Thread Derek
I agree with previous posts.

It might also be worthwhile to simplify your code to avoid unneeded 
variables:

details=Details(
name=requests.POST.get('name'), 
roof_age=requests.POST.get('roof_age'), 
email=requests.POST.get('email'),
phone=requests.POST.get('phone'), 
address=requests.POST.get('address'),
monthly_bill=requests.POST.get('monthly_bill'), 
HOA=requests.POST.get('HOA'), 
battery=requests.POST.get('battery'), 
foundation=requests.POST.get('foundation'), 
roof_type=requests.POST.get('roof_type'),
availability=requests.POST.get('availability'),
bill=requests.POST.get('bill')
)
print(details)
details.clean()
details.save()
print("The data has been saved to db")

On Sunday, 18 September 2022 at 00:25:36 UTC+2 Ryan Nowakowski wrote:

>
> On Sat, Sep 17, 2022 at 11:48:06PM +0530, Nishant Sagar wrote: 
> > While saving the values to the data to the database I'm getting this 
> Field 
> > 'roof_age' expected a number but got ('1',) 
> > 
> > How can I resolve this? 
> > Here is my views.py file 
> > def form(requests): 
> > if requests.method == 'POST': 
> > name=requests.POST['name'], 
> > # roof_age= requests.POST['roof_age'], 
> > roof_age= int(requests.POST.get('roof_age')), 
>
> You have an errant comma at the end of the line which makes roof_age a 
> tuple. Get rid of the comma. 
>
> Also, I agree with the other reply that you should probably be using a 
> Form[1] to handle POST input. 
>
> [1] https://docs.djangoproject.com/en/4.1/topics/forms/ 
>

-- 
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/91aa5b2c-4f4d-45d9-858b-872b536b719an%40googlegroups.com.


Re: Negative Stock Prevention

2022-08-30 Thread Derek
As a start, the logic checks for the model should not be in views.py but 
rather with the model object (in models.py).  You can extend the save() 
method, for example, and add the checks there.

See: 
* https://docs.djangoproject.com/en/4.1/ref/models/instances/#saving-objects
* 
https://docs.djangoproject.com/en/4.1/ref/models/instances/#what-happens-when-you-save
* 
https://docs.djangoproject.com/en/4.1/topics/db/models/#overriding-model-methods

On Monday, 29 August 2022 at 16:19:28 UTC+2 techg...@gmail.com wrote:

> Hello,
>
> Please help crack the below code, I want to prevent negative stock, and if 
> the stock is == 0, deduct it from reorder_level instead.
> Currently, the stock goes negative.
>
> models.py
>
> class Stock(models.Model):
> quantity = models.IntegerField(default='0', blank=True, null=True)
> reorder_level = models.IntegerField(default='0', blank=True, null=True)
>
> class Dispense(models.Model):
> drug_id = models.ForeignKey(Stock, 
> on_delete=models.SET_NULL,null=True,blank=False)
> dispense_quantity = models.PositiveIntegerField(default='1', blank=False, 
> null=True)
> taken=models.CharField(max_length=300,null=True, blank=True)
>
> views.py
>
> try:  
> 
> if request.method == 'POST':
> if form.is_valid(): 
> username = form.cleaned_data['taken']
> qu=form.cleaned_data['dispense_quantity']
> ka=form.cleaned_data['drug_id']
> # print(username)
> 
> 
> 
> stock= eo=Stock.objects.annotate(
> expired=ExpressionWrapper(Q(valid_to__lt=Now()), 
> output_field=BooleanField())
> ).filter(expired=False).get(id=username)
> form=DispenseForm(request.POST or None, instance=stock)
> instance=form.save()
> # print(instance)
> if quantity > 0
> instance.quantity-=qu
> instance.save()
> else:
> instance.reorder_level-=qu
> instanc.save()
>
> form=DispenseForm(request.POST or None 
> ,initial={'patient_id':queryset})
> form.save()
>
> messages.success(request, "Drug Has been Successfully Dispensed")
>
> return redirect('manage_patient_pharmacist')
> else:
> messages.error(request, "Validity Error")
>
> return redirect('manage_patient_pharmacist')
>
> context={
> "patients":queryset,
> "form":form,
> # "stocks":stock,
> "drugs":drugs,
> "prescrips":prescrips,
> "expired":ex,
> "expa":eo,
>
> }
> if request.method == 'POST':
> 
> print(drugs)
> context={
> "drugs":drugs,
> form:form,
> "prescrips":prescrips,
> "patients":queryset,
> "expired":ex,
> "expa":eo,
>
> }
> except:
> messages.error(request, "Dispensing Not Allowed! The Drug is Expired 
> ,please do a re-stock ")
> return redirect('manage_patient_pharmacist')
> context={
> "patients":queryset,
> "form":form,
> # "stocks":stock,
> "drugs":drugs,
> "prescrips":prescrips,
> "expired":ex,
> "expa":eo,
>
> }
>
> return render(request,'templates/discharge.html',context)
>
>

-- 
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/e7001283-8260-44c3-974b-03ec4ef56ed3n%40googlegroups.com.


Re: How to generate a table in pdf?

2022-06-27 Thread Derek
https://xhtml2pdf.readthedocs.io/en/latest/usage.html is what you need.

On Friday, 24 June 2022 at 16:08:10 UTC+2 kvnk...@gmail.com wrote:

>
>
>
>
> *Hi family, I created a salary calculation application.As I already 
> display the list of employees, I now have to download it using a function 
> in the VIEW folder.Please I urgently need helpThanks ...*
>

-- 
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/b7b33563-6fae-445c-8343-1dad5e976a1en%40googlegroups.com.


Re: Json Object type field in Model in Django

2022-06-10 Thread Derek
Creating:  https://docs.djangoproject.com/en/4.0/ref/models/fields/#jsonfield 
Querying: 
https://docs.djangoproject.com/en/4.0/topics/db/queries/#querying-jsonfield 

On Thursday, 9 June 2022 at 15:00:31 UTC+2 vmuk...@gmail.com wrote:

> Hii Community,
>
> can we add a field in model that stores json and we can access it's keys 
> to get there respective values, if yes please let me know and how we can 
> use that this thing too.
>
> Thanks and Regards
> Mukul Verma
>

-- 
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/8c4a4e04-ff45-4e2e-afb4-dd1eb720622en%40googlegroups.com.


Re: create_question not define error. NameError.

2022-05-03 Thread Derek
What steps did you follow to get here?  What does your code look like that 
creates this error?

(Its probably better to post actual code snippets as text rather than 
screenshots.)

On Monday, 2 May 2022 at 15:02:44 UTC+2 mdanz...@gmail.com wrote:

> Anyone is here for help?
>
> On Friday, 29 April 2022 at 11:45:48 UTC+5:30 Md Anzar wrote:
>
>> I am following Django tutorial in part 5 when I tried to test and getting 
>> error.  I need help.
>> [image: Screenshot from 2022-04-28 23-50-50.png]
>
>

-- 
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/7c241971-c05f-4c71-8536-d615ac0ca3a3n%40googlegroups.com.


Re: Help! I begginer...

2022-04-29 Thread Derek
You may need to update the version of Django you're running; the current 
source code 
(https://github.com/django/django/blob/main/django/db/models/sql/query.py) 
shows this import:

from collections.abc import Iterator, Mapping

Hope that helps.

On Tuesday, 26 April 2022 at 18:34:34 UTC+2 rikrdopr...@gmail.com wrote:

> Error:
>
>   File 
> "C:\Users\tecnico.ricardo\PycharmProjects\pythonProject01\venv01\lib\site-packages\django\db\models\sql\query.py",
>  
> line 11, in 
> from collections import Counter, Iterator, Mapping, OrderedDict
> ImportError: cannot import name 'Iterator' from 'collections' 
> (C:\Users\tecnico.ricardo\AppData\Local\Programs\Python\Python310\lib\collections\__init__.py)
> (venv01) PS C:\Users\tecnico.ricardo> 
>
>
>

-- 
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/18cccf8d-85ba-492e-ac9d-6d4a78ce7888n%40googlegroups.com.


Re: simple command line ./manage.py shell puzzle

2022-04-24 Thread Derek
Actually, there does seem to be some further issue:

echo "import datetime; [datetime.date(2022,4,e) for e in [1,2]]" > test.py

Also triggers an error when used in the Django shell, but works when run 
as  a normal Python script:

python test.py

On Monday, 25 April 2022 at 07:44:02 UTC+2 Derek wrote:

> It fails because the second datetime in your test script is taken to be a 
> variable and it is not one you have already defined; hence the error: 
> "NameError: name 'datetime' is not defined".
>
> Try this instead:
>
> echo "import datetime ; [e*e for e in [1,2]]" > test
>
> On Thursday, 21 April 2022 at 19:06:45 UTC+2 cseb...@gmail.com wrote:
>
>> Why does this fail?...
>>
>> % echo "import datetime ; [datetime for e in [1, 2]]" > test
>>
>> % ./manage.py shell < test
>>
>> Traceback (most recent call last):
>>   File "./manage.py", line 8, in 
>> django.core.management.execute_from_command_line(sys.argv)
>>   File 
>> "/usr/lib/python3/dist-packages/django/core/management/__init__.py", line 
>> 381, in execute_from_command_line
>> utility.execute()
>>   File 
>> "/usr/lib/python3/dist-packages/django/core/management/__init__.py", line 
>> 375, in execute
>> self.fetch_command(subcommand).run_from_argv(self.argv)
>>   File "/usr/lib/python3/dist-packages/django/core/management/base.py", 
>> line 323, in run_from_argv
>> self.execute(*args, **cmd_options)
>>   File "/usr/lib/python3/dist-packages/django/core/management/base.py", 
>> line 364, in execute
>> output = self.handle(*args, **options)
>>   File 
>> "/usr/lib/python3/dist-packages/django/core/management/commands/shell.py", 
>> line 92, in handle
>> exec(sys.stdin.read())
>>   File "", line 1, in 
>>   File "", line 1, in 
>> NameError: name 'datetime' is not defined
>>
>

-- 
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/bf2e86b8-6c2a-4070-a53e-3b1f8e538039n%40googlegroups.com.


Re: simple command line ./manage.py shell puzzle

2022-04-24 Thread Derek
It fails because the second datetime in your test script is taken to be a 
variable and it is not one you have already defined; hence the error: 
"NameError: name 'datetime' is not defined".

Try this instead:

echo "import datetime ; [e*e for e in [1,2]]" > test

On Thursday, 21 April 2022 at 19:06:45 UTC+2 cseb...@gmail.com wrote:

> Why does this fail?...
>
> % echo "import datetime ; [datetime for e in [1, 2]]" > test
>
> % ./manage.py shell < test
>
> Traceback (most recent call last):
>   File "./manage.py", line 8, in 
> django.core.management.execute_from_command_line(sys.argv)
>   File 
> "/usr/lib/python3/dist-packages/django/core/management/__init__.py", line 
> 381, in execute_from_command_line
> utility.execute()
>   File 
> "/usr/lib/python3/dist-packages/django/core/management/__init__.py", line 
> 375, in execute
> self.fetch_command(subcommand).run_from_argv(self.argv)
>   File "/usr/lib/python3/dist-packages/django/core/management/base.py", 
> line 323, in run_from_argv
> self.execute(*args, **cmd_options)
>   File "/usr/lib/python3/dist-packages/django/core/management/base.py", 
> line 364, in execute
> output = self.handle(*args, **options)
>   File 
> "/usr/lib/python3/dist-packages/django/core/management/commands/shell.py", 
> line 92, in handle
> exec(sys.stdin.read())
>   File "", line 1, in 
>   File "", line 1, in 
> NameError: name 'datetime' is not defined
>

-- 
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/d3b34127-73f0-47ca-919a-d9de8bae920cn%40googlegroups.com.


Re: Django

2022-04-22 Thread Derek
from app2.models import ThatModel

(assuming both apps are part of the same project)

On Thursday, 21 April 2022 at 21:47:18 UTC+2 farid...@gmail.com wrote:

> Please how do I import a model from another app. Thanks, please someone 
> should help me out
>

-- 
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/c39e9937-c819-461b-a3ea-fedeb46cc149n%40googlegroups.com.


Re: Fetching Data Between Models

2022-04-21 Thread Derek
You've already posted the same question:
https://groups.google.com/g/django-users/c/f7ZH2pcZp0s


On Wednesday, 20 April 2022 at 16:44:19 UTC+2 techg...@gmail.com wrote:

> I have a model Staff and LeaveReportStaff, I wanted to get leave_balance 
> between Total_Leave_Days and leave_days. I already used Foreignkey for 
> staff but I'm not sure if it is right to use Foreignkey again.
>
> Please advise the best way forward.
>
> class Staff(models.Model):
> Total_Leave_Days = models.PositiveIntegerField(default=0)
> course = models.ForeignKey(Course, on_delete=models.DO_NOTHING, 
> null=True, blank=False)
> admin = models.OneToOneField(CustomUser, on_delete=models.CASCADE)
>
>
> class LeaveReportStaff(models.Model):
> staff = models.ForeignKey(Staff, on_delete=models.CASCADE)
> start_date = models.DateField()
> end_date = models.DateField()
> leave_type = models.CharField(choices=LEAVE_TYPE, max_length=25, 
> null=True, blank=False)
>
> @property
> def leave_days(self):
> return (self.end_date - self.start_date).days
>
> @property
> def leave_balance(self):
> return (self.Total_Leave_Days - self.leave_days)
>
>

-- 
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/498d046c-84e9-4ee6-914c-14a373c50625n%40googlegroups.com.


Re: Calculations Between Models

2022-04-20 Thread Derek
Not sure what the "@aproperty" are here for, but in your views.py file, you 
could do this calculation, passing in the ID of the staff record:

from .models import Staff, LeaveReportStaff

def get_leave_balance(staff_id):
total_leave_days = Staff.objects.get(pk=staff_id)
leave_reports = LeaveReportStaff.objects.filter(staff=staff_id)
total_leave_reports = 0
for leave in leave_reports:
total_leave_reports = total_leave_reports + (leave.end_date - 
leave.start_date).days
return total_leave_days - total_leave_reports  # leave balance


On Tuesday, 19 April 2022 at 17:34:33 UTC+2 techg...@gmail.com wrote:

> Hello,
>
> I have a model Staff and LeaveReportStaff, I wanted to get leave_balance 
> between Total_Leave_Days and leave_days.
>
> Please advise the best way forward.
>
> class Staff(models.Model):
> Total_Leave_Days = models.PositiveIntegerField(default=0)
> course = models.ForeignKey(Course, on_delete=models.DO_NOTHING, 
> null=True, blank=False)
> admin = models.OneToOneField(CustomUser, on_delete=models.CASCADE)
>
> class LeaveReportStaff(models.Model):
> staff = models.ForeignKey(Staff, on_delete=models.CASCADE)
> start_date = models.DateField()
> end_date = models.DateField()
> leave_type = models.CharField(choices=LEAVE_TYPE, max_length=25, 
> null=True, blank=False)
>
> @property
> def leave_days(self):
> return (self.end_date - self.start_date).days
>
> @property
> def leave_balance(self):
> return (self.Total_Leave_Days - self.leave_days)
>
>

-- 
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/bc9885b8-0cae-4958-bf4e-7a542a55459an%40googlegroups.com.


Re: Logging: set default values for custom keys in custom formatters OR choose formatter based on logger

2022-04-12 Thread Derek
Re issue (1):

https://github.com/django/django/blob/main/django/utils/log.py#L31 shows 
how Django uses its own JSON format in  `settings.py` to set a link to its 
(local) own custom class `ServerFormatter`, which in turn inherits from 
Python's logging.Formatter. So it should be possible to create your own 
formatter class and reference it in the same kind of way.

(As an aside: you can do really interesting things with a customer 
formatter e.g. see 
https://alexandra-zaharia.github.io/posts/make-your-own-custom-color-formatter-with-python-logging/)

I don't understand what you're trying to achieve in (2), so cannot comment.

On Sunday, 10 April 2022 at 18:53:31 UTC+2 ad...@khaleesi.ninja wrote:

> Hi all,
>
> I'm trying to extend the formatter for console logging with custom keys. 
> But I've run into two problems while doing that:
>
> 1) Root log messages of course don't provide these custom keys in their 
> extra dict, so they throw errors. Looking at the official Python 
> documentation, it is possible to specify defaults for a formatter (
> https://docs.python.org/3/library/logging.html#logging.Formatter), but 
> Django doesn't support such a thing when trying to set it via the 
> settings.py (as in: the formatters entry in the LOGGING specification in 
> the settings.py doesn't support this).
>
> 2) So I looked into using that formatter only for my own log messages, for 
> which I can control the extra dict passed to them. But it doesn't seem to 
> be possible to provide two formatters for a single handler (kinda makes 
> sense, since at that point, how would the handler choose the formatter?) 
> But if I specify two different handlers of type logging.StreamHandler, 
> only one of them seems to work (and the other handler's messages just 
> aren't visible in the console output).
>
> Does anyone have a solution for this?
>
> If not, do people think it's worth requesting support for the defaults 
> field for formatters specified in the settings.py LOGGING configuration?
>
> Thanks!
> -M
>

-- 
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/6e963a05-354e-4320-83a9-b57e2a308527n%40googlegroups.com.


Re: xlsx file data pasing into array to pgadmin using python

2022-03-15 Thread Derek
If you are working purely at database level, perhaps best to ask on a 
PostgreSQL Mailing List?

On Monday, 14 March 2022 at 16:27:02 UTC+2 boddulur...@gmail.com wrote:

> database function how to write data saave into table in array data

-- 
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/8acdbc26-5eb0-4cb6-999d-1dce7f0cc08an%40googlegroups.com.


Re: How to create dynamic models in django??

2022-03-10 Thread Derek
I'm not quite sure how these requirements have arisen as you have not 
provided any context as to the actual user or business needs.  In my 
experience,  most businesses and science organisations  understand very 
clearly what kinds of data they need to store and what they need to do with 
that data.   This makes it possible for the developers to design and 
 implement well-structured SQL  databases.

If,  for some reason, this is really not your use case then, as the other 
commenters have suggested,  it's likely that Django is not a good fit for 
your needs.  Perhaps you should consider a NoSQL  solution 
(https://www.mongodb.com/nosql-explained/when-to-use-nosql) instead;  and 
explore the use of  its associated technologies which can meet your stated 
requirements.

On Thursday, 10 March 2022 at 01:55:18 UTC+2 Ryan Nowakowski wrote:

> On Sun, Feb 27, 2022 at 09:10:05AM +0530, Prashanth Patelc wrote:
> > How to create dynamic models in django rest framework?
> > Is there any chance to create dynamic models with APIs
> > 
> > Any examples please send me thanks in advance..
> > 
> > 1) Requirement is need create table name and fields in frontend
> > 2) we are getting the data and store in to the db create db structure
> > 3) get the table name and fields create table in backend  
> store
> > to
> > 4)this code don't update or add into the models
> > 5)store the data into the tables
> > 4)get the data into the tables using orm or any raw queries
>
> The WQ project uses the Entity-Attribute-Value data model:
>
> https://v1.wq.io/1.2/docs/eav-vs-relational
>

-- 
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/a02e1d2a-b640-4b5e-ba65-bebcba8de66an%40googlegroups.com.


Re: collectstatic files chown'ed by root

2022-02-15 Thread Derek
I literally spent the last few days trying to fix this same issue (apart 
from your "Django SECRET_KEY in a .env file" problem, which I don't 
understand as it does not seem related).

There are numerous suggestions on Stack Overflow and various blogs; which 
either don't work or are too complex to understand and implement.

What worked for me was:

1. Using the default, non-root user (in my case called "django")  to create 
and set permissions on a 'staticfiles' directory as part of the Django 
container build
2. NOT setting a default, non-root user at the end of the Dockerfile used 
for the Django container build
3. Adding these lines to the end of the 'entrypoint' script:
chown -R django:django /app/staticfiles
exec runuser -u django "$@"
4. Adding the "python /app/manage.py collectstatic --noinput" command into 
the "start" script

In my case (you did not state yours) the staticfiles directory is mounted 
outside the container, and the same outside mount point is also accessed by 
the nGinx container to serve the static files.

Many folks have also commented about "hackiness" in this process, but it 
comes down to file permissions in Docker not being independent of those in 
the host; and there is a LOT of reading around that if you want to dig into 
it. IMO, its not a "workaround" if you just actually do need to work with 
multiple permissions at different points in a process.

HTH
Derek




On Monday, 14 February 2022 at 16:05:33 UTC+2 Tim wrote:

> Hi all,
> I'm deploying Django 4 via docker-compose. For security reasons, the 
> Dockerfile creates a non-root user before running the entrypoint.sh script 
> (which does migrations, collectstatic and starts the server with gunicorn). 
> All app files are "chown"ed by this non-root user.
>
> Everything works fine except for the collectstatic command (in 
> entrypoint.sh), which creates the "staticfiles" directory but it's owned by 
> root. This leads to permission denied errors when the collectstatic command 
> tries to delete a static file.
>
> My question: Why does collectstatic assign the folder to "root" despite 
> the non-root user calling the collectstatic command? How to prevent this?
>
> I tried doing the collectstatic command before switching to the non-root 
> user (in the Dockerfile) which works. But it stops working when I put the 
> Django SECRET_KEY in a .env file (as we should in production) since this 
> env var is not available during docker build time.
>
> Now I could find a hackier way by making the secret key available during 
> build time or switching back to a root user in entrypoint.sh, but all of 
> this is a bad workaround in my opinion.
>
> I'm sure everyone deploying Django with docker and being mindful of 
> security has come across this - Any hints about why collectstatic is owned 
> by root? Is this a bug?
>
> Should I add additional details?
>
> Thanks for any tips!
> Tim
>

-- 
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/f2dd85b6-c787-4109-9855-b9b2fe05ce26n%40googlegroups.com.


Re: Django versus competitors survey

2022-02-12 Thread Derek
Apologies about my assumption -  it seemed from your example that perhaps 
your experience was creating websites using WordPress, rather than writing 
actual code.

Its hard to give a general answer to your question;  I think the popularity 
of Django speaks to the fact that single-threading is not a key issue for 
most use cases; and there other ways to scale out those parts of your 
application that may be resource intensive e.g. using Celery to off-load 
data processing to the back end - 
see https://www.caktusgroup.com/blog/2021/08/11/using-celery-scheduling-tasks

As to issues with Python's actual speed; numerous Very Large companies have 
used it power applications running at global scale - 
see https://brainstation.io/career-guides/who-uses-python-today - so that 
is a good argument for its effectiveness.  Having said that, there are 
times when parts of your application could use speeding up - and Python 
offers numerous ways to enable that. But I'd argue to first get it working, 
and then get it working faster; a path that Python supports well.  We had a 
use case recently where we swopped out FastAPI (a solid, well-written 
Python app) for Actix (Rust-based app) because of the need for extremely 
high through-puts.  Fortunately, use of a micro-services approach makes 
this feasible.
 
HTH

PS - for a article with a good overview (and practical examples) on 
handling threading and concurrency in Python, have a look 
at 
https://www.toptal.com/python/beginners-guide-to-concurrency-and-parallelism-in-python

On Thursday, 10 February 2022 at 18:35:47 UTC+2 michae...@gmail.com wrote:

> On Wednesday, February 9, 2022 at 8:39:01 AM UTC-5 Derek wrote:
>
>> Hi Michael
>>
>> I think you may be be comparing apples and oranges and this could be 
>> because it seems you're more of a software user than a software builder.
>>
>
> "it seems you're more of a" ... BUZZ wrong answer. No. As I stated, I am 
> coming at this from more of a pure soft dev perspective, with 30+ years of 
> industry experience; not niche web, CMS spheres, per se... Rather, the 
> questions here are more one of 'sizing up' if you will Django, Python, etc. 
> That being established... 
>
> Django is used to build web-based applications, primarily those with a 
>> database backend.  One such type of application is a CMS (other types could 
>> be an online store or an asset management system etc).  If all you need is 
>> a CMS, and you're OK with Django/Python as the underlying technology, then 
>> look to tools like https://www.django-cms.org/en/ or https://wagtail.org/ 
>> - you can compare their features to a more widely-known one such as 
>> WordPress.
>>
>
> One 'comparable feature' so to say with WP seems to be that the PHP 
> runtime is also single process single threaded, as Python's is, the core 
> tech fueling the Django experience. Is that an issue? Versus, say, 
> multi-threaded more async counterparts, ASP.NET, .NET Framework, dotnet 
> core, and so on?
>  
>
>> HTH.
>>
>
> Appreciate the response, thank you.
>  
>
>> On Tuesday, 8 February 2022 at 17:49:28 UTC+2 michae...@gmail.com wrote:
>>
>>> Hello,
>>>
>>> I am engaged in a web site development effort, and I think the core tech 
>>> has got to be a CMS of some sort. I am coming from a 'pure' soft. dev. 
>>> background, if you will, including 'web sites', API, etc, but re: Django, I 
>>> am trying to gauge 'ecosystem' if you will and interested to hear from 
>>> peers among the community thoughts, as compared/contrasted with competitors 
>>> such as WordPress, Orchard Core, etc.
>>>
>>> Maturity of Django as compared/contrasted with competitors. For 
>>> instance, I understand that possibly 'theming' is something that was only 
>>> just introduced to Django in recent versions? 7, 8, 9, 10? Something like 
>>> that. Only now? Seems like 'others' have been able to do that for some time 
>>> now?
>>>
>>> Marketshare concerns. How much of a market share, adoption level is 
>>> there with Django versus others?
>>>
>>> Technical questions primarily stemming from the nature of the Python 
>>> runtime, being that it is effectively single processor, single threaded. Is 
>>> that ever a concern? Versus others who support asynchronous and so forth.
>>>
>>> From a workflow perspective, ability to support 'development' inner and 
>>> outer loops, what to treat as 'source code', pushing updates to different 
>>> servers, testing, staging, production, etc. Can any of that be captured to 
>>> a git repository, for instance, or is it all a function of the backend 
>>> database

Re: Django versus competitors survey

2022-02-09 Thread Derek
Hi Michael

I think you may be be comparing apples and oranges and this could be 
because it seems you're more of a software user than a software builder.

Django is used to build web-based applications, primarily those with a 
database backend.  One such type of application is a CMS (other types could 
be an online store or an asset management system etc).  If all you need is 
a CMS, and you're OK with Django/Python as the underlying technology, then 
look to tools like https://www.django-cms.org/en/ or https://wagtail.org/ - 
you can compare their features to a more widely-known one such as WordPress.

HTH.


On Tuesday, 8 February 2022 at 17:49:28 UTC+2 michae...@gmail.com wrote:

> Hello,
>
> I am engaged in a web site development effort, and I think the core tech 
> has got to be a CMS of some sort. I am coming from a 'pure' soft. dev. 
> background, if you will, including 'web sites', API, etc, but re: Django, I 
> am trying to gauge 'ecosystem' if you will and interested to hear from 
> peers among the community thoughts, as compared/contrasted with competitors 
> such as WordPress, Orchard Core, etc.
>
> Maturity of Django as compared/contrasted with competitors. For instance, 
> I understand that possibly 'theming' is something that was only just 
> introduced to Django in recent versions? 7, 8, 9, 10? Something like that. 
> Only now? Seems like 'others' have been able to do that for some time now?
>
> Marketshare concerns. How much of a market share, adoption level is there 
> with Django versus others?
>
> Technical questions primarily stemming from the nature of the Python 
> runtime, being that it is effectively single processor, single threaded. Is 
> that ever a concern? Versus others who support asynchronous and so forth.
>
> From a workflow perspective, ability to support 'development' inner and 
> outer loops, what to treat as 'source code', pushing updates to different 
> servers, testing, staging, production, etc. Can any of that be captured to 
> a git repository, for instance, or is it all a function of the backend 
> database upon which Django, or its competitors, is built?
>
> Backend (or client side) integrations, because client side and/or backend 
> integration is a possibility, support for calling into dotnet core, for 
> instance, because it is 'what I know', or others, perhaps even C/C++ native 
> backend processing, etc. Realizing some of that is probably a hosting 
> issue, whether we are multi-tenant, dedicated server, etc.
>
> It's a work in process, so please forgive the throwing of mud on the wall. 
> No formal decisions have been made yet, this is exploratory on my part at 
> the moment.
>
> Thanks so much., best regards,
>
> Michael W. Powell
>
>

-- 
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/9279cdfa-0463-451a-8838-dceed17b5cc2n%40googlegroups.com.


Re: Barcode

2022-02-02 Thread Derek
We implemented bar coding on the back end - e.g., to generate a PDF which 
the client then prints.

One library you can use for this is:
https://pypi.org/project/treepoem/


On Wednesday, 2 February 2022 at 02:05:56 UTC+2 
andres@uaiinpebi-cric.edu.co wrote:

> Does anyone have experience with UCC/EAN-128 barcodes? I am using a 
> javascript barcode js library with django to implement the barcode but it 
> is generating errors when reading if anyone knows any library or api that 
> can be used that complies with the UCC/EAN-128 parameters that can provide 
> me with information
>

-- 
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/6ea4902e-9a13-4aad-9c8a-84a217d2a991n%40googlegroups.com.


Re: Database design

2022-01-23 Thread Derek
The best approach is for the Django/DB devs to create these fields (and 
forms) in advance for the users to enter data.

If you want users to add "key/pair" type data which is not known in 
advance, look to adding a JSON column to your table; see:
https://www.postgresql.org/docs/14/datatype-json.html

On Sunday, 23 January 2022 at 14:37:55 UTC+2 msredd...@gmail.com wrote:

> Ohh you want create custom fields in forms
>
>
> Take input, select, textarea tags, make them their own fields but save all 
> of these in fields in one table with types and max values all of the 
> attributes of tags 
>
>
> Finally show then what they chosen 
>
> On Sun, 23 Jan 2022 at 2:28 PM, Prashanth Patelc  
> wrote:
>
>> Dear Django users,
>>
>> I need some information regarding Django models, I would like to know is 
>> there any way to 
>> create Django models through frontend or can we create models by super 
>> admin. Kindly share any tutorials or any examples available.
>>
>> Example:
>> we are create models in django
>> like below fields 
>> ===
>> class modelname(models.Model):
>>id = models.PrimeryKey(auto_now_add=true)
>>name =models.CharField()
>>salary =models.DecimalField()
>>
>> But my concern is create model name and fields like in html or super 
>> admin can do
>>
>> ===
>> => he will enter values in variables with appropriate field type.
>>  for eg., "name char type", "Salary decimal field" and so on..
>> =>When the user enter data into application it should directly store in 
>> database in the form of tables and rows..
>>
>> Regards;
>> Prashanth
>> email : prashan...@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...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/CAMCU6Co2CysGZ_ZHrFW5XJEregFhR6pdZS3i%2BJkLvVsvBqnUOQ%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/2c4ee760-b695-44d4-87b0-dd05ad1d372bn%40googlegroups.com.


Re: Django reportViewer

2021-12-15 Thread Derek
This seems to be referring to a Microsoft app 
(https://www.thereportviewer.com/) that has nothing to do with Django.

You can, of course, use Django to build a web page that looks similar to 
this, assuming you have access to the underlying database.

On Tuesday, 14 December 2021 at 16:01:39 UTC+2 eugenet...@gmail.com wrote:

> Dear Team,
>
> Is there anyway I can use reportViewer in Django application so that I can 
> have something similar to below image:
>
> [image: image.png]
>
> Let me know how I can do it if it is possible in the django app.
>
> Regards, 
>
>
> *Eugene*
>
>
>

-- 
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/41a51ebf-6a02-4cd8-884e-71085c2040c6n%40googlegroups.com.


Re: Re-write an application from Turbogear to Django.

2021-11-27 Thread Derek
Agreed. You could also consider keeping Dojo and upgrading to the current 
version.

On Thursday, 25 November 2021 at 19:41:52 UTC+2 sutharl...@gmail.com wrote:

> I would have chosen the first option, since we can have some relationships 
> in the database and once all the apis are ready. We can easily pick React 
> part.
>
> On Thu, 25 Nov 2021 at 23:03, Stamatia  wrote:
>
>> Hi,
>>
>> I have a question that might need discussion.
>> I have a legacy application on Turbogears(1.5) and an old version of 
>> Dojo.js on front end and I want to re-write it on Django and Reactjs. 
>>
>> What is the best approach to do it?
>> Is it better: 
>> 1. to start with backend and re-write everything on Django and then to 
>> change the front end
>> 2. to change frontend and backend at the same time (step by step - page 
>> by page) 
>> 3. or to start with front end, apply the changes to current application 
>> and then to change backend?
>>
>> Thanks,
>> Stam
>>
>>
>> -- 
>> 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 view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/84a7c2ee-5352-4231-8595-169b780cf3c9n%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/240a402c-0f81-4595-9d8e-ca876dd11d19n%40googlegroups.com.


Re: Mouse movement detection and processing from client UI

2021-10-27 Thread Derek
I am not sure about the others, but certainly for map clicks you'll need 
JavaScript  e.g.
https://docs.mapbox.com/mapbox-gl-js/example/popup-on-click/
Of course, the page itself, with JS code links, snippets and supporting 
data can be generated via Django in the normal way.

HTH


On Wednesday, 27 October 2021 at 04:03:16 UTC+2 lego.th...@gmail.com wrote:

> So there are Python packages out there that can handle mouse movement 
> detection locally. But for a Django app, how do we go about do this? 
> Clearly we cannot have any processing power on the client machine. Below 
> are some examples to be more specific:
> 1 - An e-commerce page where buyer clicks, drags (i.e. holds the mouse) 
> and drops a picture of an item from shelf to cart.
> 2 - A web game where player clicks, drags and drops things from one 
> location on the screen to another.
> 3 - Web page responds to location of mouse on screen (i.e. coordinates) 
> such as GPS-related apps with real map.
>
> 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/c88b73ab-8c63-451d-919c-6d5550b8c1f7n%40googlegroups.com.


Re: Quick question for web hosting production

2021-10-13 Thread Derek
Here's a similar question on StackOverflow:

https://stackoverflow.com/questions/65141036/deploy-react-and-django-with-nginx-and-docker


On Friday, 8 October 2021 at 16:17:27 UTC+2 patz...@gmail.com wrote:

> I want to ask a quick question guys that, is it possible to host 2 apps in 
> one cloud service? like for example, angular for the front end and django 
> for the backend? and they would use one ip address right but on a different 
> port?
>
>
>

-- 
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/5599824d-f931-4e2b-aadc-34bfc35e7ea7n%40googlegroups.com.


Re: Listing and Searching fields in another table

2021-10-06 Thread Derek
Obviously you will be searching in related table. 

So if you have models.py like:

class Author(models.Model):
first_name = models.CharField(max_length=100)
last_name = models.CharField(max_length=100)

class Book(models.Model):
title = models.CharField(max_length=200)
author = models.ForeignKey(Author)

Then in your admin.py for book:

search_fields = (
'title', 'author__first_name',  'author__last_name', )

HTH

On Tuesday, 5 October 2021 at 22:37:22 UTC+2 iyanuol...@gmail.com wrote:

> Good day, I would like to use the list_display and search_fields functions 
> in one table on the Django admin page to display and search for a field in 
> another table. Could I please get any pointers on how to go about this? 
>
>  
>

-- 
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/7db8ff9d-2cde-4647-9490-22561cd98bffn%40googlegroups.com.


Reverse look fails when importing from the admin for an app

2021-10-03 Thread Derek
My pytest suite is currently not working, as the reverse lookup is failing
for admin views; for example, trying to access
`reverse('admin:myapp_mymodel_changelist')` or
`reverse_lazy('admin:myapp_mymodel_changelist')`.

I have narrowed down the cause to the trigger being *any* kind of import
being made from the `admin.py` code for that app; the available URLs are
still there for all the other apps but *not* for the one being imported.

In `django/urls/resolvers.py` package, the available possible matches are
determined here:

possibilities = self.reverse_dict.getlist(lookup_view)

And one can add a debug statement which shows all the keys:

keys = [key for key in [*self.reverse_dict] if isinstance(key, str)]
print(keys)

Some basic test code, which I run in the Django shell, demonstrates how the
failure is triggered, and shows that this is not an artefact related to the
tests themselves:

from django.core.urlresolvers import reverse_lazy
from myapp.admin import MyModelAdmin
print(reverse_lazy('admin:myapp_mymodel_changelist'))

But this passes:

from django.core.urlresolvers import reverse_lazy
print(reverse_lazy('admin:myapp_mymodel_changelist'))

i.e. if I comment out the import line the code works, otherwise it fails.

Any ideas on why Django is failing when importing from the app's admin?

Thanks
Derek

-- 
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/CAF1Wu3Mdz08vD74vsBWQOT1UNDTqRXOV0C57rz%3DiXXH-TPiFCA%40mail.gmail.com.


Re: How can add multiple forms according to input enter number or with click add more button

2021-09-26 Thread Derek
Have a look at https://django-formtools.readthedocs.io/en/latest/
This includes the ability to skip steps based on information already 
supplied -
https://django-formtools.readthedocs.io/en/latest/wizard.html#conditionally-view-skip-specific-steps


On Thursday, 23 September 2021 at 20:37:03 UTC+2 m.abu.b...@gmail.com wrote:

> I have an input field where the will customer add a number for buy 
> membership then will get forms according to numbers 1,2, or 5 then will 
> show 1,2, or 5 forms with input fields in which will add data.
>
> How can add this type of functionality? Because I'm a beginner in python 
> Django. Thanks
>
> For example:
>
>1. 
>
>customer will come to the site and click on buy membership
>2. 
>
>the first page will How many Memberships do you want to buy? ==> input 
>Field in which add 1,2, or 5
>3. 
>
>based on how many members enter a show a page to collect information 
>of members
>4. 
>
>3rd step collect customer/parent information
>
>

-- 
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/d15c0e7b-043b-4f7e-8ebe-a622037a4058n%40googlegroups.com.


Re: UML to Django models

2021-08-26 Thread Derek
There is not sufficient data in that image to create models.  You don't 
know the field types, for example.

Once you have those, it should not be too hard e.g.:

from django.db import models

class Product(models.Model):
product_id = models.AutoField()
name = models.CharField( max_length=255)
date_introduction = models.DateField()
comment = models.TextField()

#etc.

You'll need to use ForeignKey fields to link related tables, of course.

HTH.

On Thursday, 26 August 2021 at 10:28:23 UTC+2 abubak...@gmail.com wrote:

> can anyone help me?
>
> On Thu, Aug 26, 2021 at 9:32 AM DJANGO DEVELOPER  
> wrote:
>
>> Currently, I am working on an inventory management system and I have got 
>> some UML diagrams and want to convert those uml diagrams into django 
>> models. So can anyone guide me on how to convert those UML diagrams into 
>> django models?
>> an example is below of uml diagram
>>
>> -- 
>> 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 view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/d7cc08c3-cb88-422b-8cb3-a15130abeba1n%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/74f7d899-ceb8-42a4-8809-fdd5aac48625n%40googlegroups.com.


Re: Django admin filters + select2 + loading many options asynchronously

2021-08-05 Thread Derek
Alternatively, there is 
: https://pypi.org/project/django-admin-autocomplete-filter/ 

(My own issue with that one s that does not necessarily match any custom 
styling, but that is probably not a problem for most.)

On Friday, 6 August 2021 at 07:53:35 UTC+2 Derek wrote:

> You mean like https://pypi.org/project/django-autocomplete-light/ ?
>
> On Wednesday, 4 August 2021 at 20:45:16 UTC+2 Federico Capoano wrote:
>
>> Hi everyone,
>>
>> when adding adming filters by foreign key in the admin, sometimes the 
>> possible values are too many to load.
>>
>> So I am thinking, why not load values asynchronously and show these with 
>> select2?
>> Probably only a certain number of values should be fetched and then while 
>> scrolling more values should be loaded.
>>
>> I am wondering, is there any solution for this already?
>>
>> Thanks in advance
>> Best regards
>>
>

-- 
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/04001c01-ae6c-410d-a054-8b4a0c5e6c93n%40googlegroups.com.


Re: Django admin filters + select2 + loading many options asynchronously

2021-08-05 Thread Derek
You mean like https://pypi.org/project/django-autocomplete-light/ ?

On Wednesday, 4 August 2021 at 20:45:16 UTC+2 Federico Capoano wrote:

> Hi everyone,
>
> when adding adming filters by foreign key in the admin, sometimes the 
> possible values are too many to load.
>
> So I am thinking, why not load values asynchronously and show these with 
> select2?
> Probably only a certain number of values should be fetched and then while 
> scrolling more values should be loaded.
>
> I am wondering, is there any solution for this already?
>
> Thanks in advance
> Best regards
>

-- 
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/3b5ee45a-85ab-424e-beea-8d66cf5116b3n%40googlegroups.com.


Re: Conmect two docker container

2021-08-01 Thread Derek
Docker has a short tutorial on their website:

https://docs.docker.com/samples/django/


On Sunday, 1 August 2021 at 04:48:54 UTC+2 parampal...@gmail.com wrote:

> I have two docker container one is postgresql 
>
>
>
>
> And second one is django container 
> how i connect this two container 
>
> Sorry for weak english
>

-- 
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/d45eb7b7-ffdb-4e79-ab8c-72f04346fd13n%40googlegroups.com.


Re: complex math calculation from query set

2021-07-21 Thread Derek
Ignore the "'distance': distance" in the return - that should not be there.

On Wednesday, 21 July 2021 at 15:55:08 UTC+2 Derek wrote:

> See:  
> https://stackoverflow.com/questions/54412377/adding-values-to-django-queryset
>  
>
> VIEW
>
> def position_view(request):
>
> packet_data = 
> TncData.objects.exclude(lat=0).order_by('-dt_heard')[:100]
> for packet in packet_data:
> *# my complex math calculation*
> *packet.distance = "# complex math formula using packet.lat and 
> packet.lon"*
>
> return render(
> request, 
> 'main/position.html',
> {'packet_data': packet_data, 'distance': distance})
>
> TEMPLATE
>
> *# suggest you use a better term than "field" => maybe "record"?*
> {% for field in packet_data %}
> 
> {{field.callsign}}
> {{field.lat|floatformat:2}} N 
> {{field.lon|floatformat:2}} W 
> 
> *{{field.distance}}*
>
>
> HTH!
>
> On Tuesday, 20 July 2021 at 22:25:04 UTC+2 mab.mo...@gmail.com wrote:
>
>> Hello,
>>
>> I am trying to perform a complex math calculation from a django query 
>> set. How can I pass the results to the template for display? Annotations 
>> won't work since the math is not a simple sum, diff or average. 
>>
>> MODEL
>>
>> class TncData(models.Model):
>> callsign = models.TextField(max_length=20)
>> lat = models.FloatField(null=True, blank=True, default=None)
>> lon = models.FloatField(null=True, blank=True, default=None)
>> path = models.TextField(max_length=250)
>> message = models.TextField(max_length=250)
>> dt_heard = models.DateTimeField(auto_now_add=False)
>>
>> def __str__(self):
>> return str(self.callsign)
>>
>> VIEW
>>
>> def position_view(request):
>>
>> packet_data = 
>> TncData.objects.exclude(lat=0).order_by('-dt_heard')[:100]
>>
>> *# my complex math calculation*
>> * # need to do something like append distance to packet_data like 
>> packet_data.distance*
>>
>> *distance = "# complex math formula using packet_data.lat and 
>> packet_data.lon"*
>>
>> return render(request, 'main/position.html', 
>> {'packet_data':packet_data,})
>>
>> TEMPLATE
>>
>> {% for field in packet_data %}
>>
>> 
>> {{field.callsign}}
>> {{field.lat|floatformat:2}} N 
>> {{field.lon|floatformat:2}} W 
>> 
>> *{{packet_data.distance}}*
>> {{field.dt_heard|date:"D m/d H:i"}}
>> 
>>
>> {% endfor %}
>>  
>>
>>

-- 
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/4b95c65b-c341-46cd-8125-1b13409c7bb9n%40googlegroups.com.


Re: complex math calculation from query set

2021-07-21 Thread Derek
See:  
https://stackoverflow.com/questions/54412377/adding-values-to-django-queryset 

VIEW

def position_view(request):

packet_data = TncData.objects.exclude(lat=0).order_by('-dt_heard')[:100]
for packet in packet_data:
*# my complex math calculation*
*packet.distance = "# complex math formula using packet.lat and 
packet.lon"*

return render(
request, 
'main/position.html',
{'packet_data': packet_data, 'distance': distance})

TEMPLATE

*# suggest you use a better term than "field" => maybe "record"?*
{% for field in packet_data %}

{{field.callsign}}
{{field.lat|floatformat:2}} N 
{{field.lon|floatformat:2}} W 

*{{field.distance}}*


HTH!

On Tuesday, 20 July 2021 at 22:25:04 UTC+2 mab.mo...@gmail.com wrote:

> Hello,
>
> I am trying to perform a complex math calculation from a django query set. 
> How can I pass the results to the template for display? Annotations won't 
> work since the math is not a simple sum, diff or average. 
>
> MODEL
>
> class TncData(models.Model):
> callsign = models.TextField(max_length=20)
> lat = models.FloatField(null=True, blank=True, default=None)
> lon = models.FloatField(null=True, blank=True, default=None)
> path = models.TextField(max_length=250)
> message = models.TextField(max_length=250)
> dt_heard = models.DateTimeField(auto_now_add=False)
>
> def __str__(self):
> return str(self.callsign)
>
> VIEW
>
> def position_view(request):
>
> packet_data = 
> TncData.objects.exclude(lat=0).order_by('-dt_heard')[:100]
>
> *# my complex math calculation*
> * # need to do something like append distance to packet_data like 
> packet_data.distance*
>
> *distance = "# complex math formula using packet_data.lat and 
> packet_data.lon"*
>
> return render(request, 'main/position.html', 
> {'packet_data':packet_data,})
>
> TEMPLATE
>
> {% for field in packet_data %}
>
> 
> {{field.callsign}}
> {{field.lat|floatformat:2}} N 
> {{field.lon|floatformat:2}} W 
> 
> *{{packet_data.distance}}*
> {{field.dt_heard|date:"D m/d H:i"}}
> 
>
> {% endfor %}
>  
>
>

-- 
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/dfe26aa8-1947-4576-9700-2fec733894e7n%40googlegroups.com.


Re: Looking for help to add quantity field in my food ordering project

2021-07-16 Thread Derek
>From your Order model, it seems that all the user would need to do is 
supply the value of "count" representing multiples of one item in a single 
order.

On Thursday, 15 July 2021 at 15:35:37 UTC+2 tiwar...@gmail.com wrote:

> Hello community!
> I hope you all are in best health. I've been working on developing a food 
> ordering site in Django, pretty much of the work is done, but I can't 
> figure out how to let a user select multiple quantity of a same item in a 
> single order. 
> The code is available on GitHub 
>  and to add the 
> quantity feature, there are two more active branches on the site.
> Since it is only my second Django project, I really wish it gets completed.
> If you feel you can help, please let me know.
> Any kind of help will be highly appreciable.
> 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/7a36ed5a-88af-4287-92ef-c7008b0fd87bn%40googlegroups.com.


Re: Real-time dashboard method after delivering restapi from outside

2021-06-15 Thread Derek
At a guess, I'd say you will need Django Channels - many blogs and 
tutorials out there, but here is one good worked example:

https://blog.logrocket.com/django-channels-and-websockets/

On Monday, 14 June 2021 at 15:32:51 UTC+2 lkh...@gmail.com wrote:

> It is currently returning after receiving an api request from another 
> system. I want to update the dashboard to Ajax after returning the request, 
> but I can't find a way. Can you tell me how to send a signal from 
> javascript or how to transfer it to JsonResponse? I don't know how to give 
> it to you because the template is different.  
>

-- 
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/7f300569-d9a0-4b32-87cd-0678a43f7022n%40googlegroups.com.


Re: [Solved] SVG widget for the Admin

2021-06-07 Thread Derek
Good to hear!  Django once again proving capable, once you figure it out.

Am reminded of the Zen:

"There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch."


On Mon, 7 Jun 2021 at 10:00, Mike Dewhirst  wrote:

> Thanks Derek - it is now working as follows ...
>
>
>  class Chemical(models.Model):
> ...
> ddstructure = models.TextField(null=True, blank=True, verbose_name="2D
> structure")
> ...
>
>
> class Svg_AdminTextareaWidget(AdminTextareaWidget):
> def render(self, name, value, attrs=None, renderer=None):
> if value:
> return force_text(self.format_value(value))
>
>
> class ChemicalAdmin(admin.ModelAdmin):
> ...
> def formfield_for_dbfield(self, db_field, request, **kwargs):
> if db_field.name == 'ddstructure':
> kwargs['widget'] = Svg_AdminTextareaWidget
> return super().formfield_for_dbfield(db_field, request, **kwargs)
> ...
>
> Cheers
>
> Mike
>
>
> On 7/06/2021 11:50 am, Mike Dewhirst wrote:
>
> On 6/06/2021 6:14 pm, Derek wrote:
>
> RE - "I've looked at the AdminTextareaWidget which is probably based on
> the TextInput built-in widget but see no way to influence what it does. "
> and "How do I get it to display inline in the proper place?"
>
> There seems to be similar question on SO:
>
>
> https://stackoverflow.com/questions/6239966/add-custom-html-between-two-model-fields-in-django-admins-change-form
>
> The answer with AdminFooWidget() and FooAdminForm() seems closest to your
> use case.
>
>
> Thanks for that. Unfortunately the answer at that link is ten years old
> and I think Django Admin must have moved on since then. I'm still trying to
> debug an inexplicable KeyError but I think I understand the approach.
>
> I'll keep trying
>
> Cheers
>
> mike
>
>
>
> On Sun, 6 Jun 2021 at 09:56, Mike Dewhirst  wrote:
>
>> On 4/06/2021 5:15 pm, Derek wrote:
>>
>> Hi Mike
>>
>> The SVG is not going to display as SVG in a *form* - for that you'd need
>> a widget, or perhaps just let users edit the text.
>>
>>
>> OK - I'm outta my depth here. I've looked at the AdminTextareaWidget
>> which is probably based on the TextInput built-in widget but see no way to
>> influence what it does. In theory I'd create a new widget inheriting from
>> that and use mark_safe() somehow.
>>
>> Then I would need to tell the admin form to use it for my ddstructure
>> field.
>>
>> BUT see my template effort below
>>
>>
>> Did you try displaying in the normal admin lists? This was my
>> understanding of where you wanted to see it and the code snippets I posted
>> were for that purpose.
>>
>> If you want to see it as "read only" in the form, but shown as SVG,
>> perhaps you need a custom model template (
>> https://docs.djangoproject.com/en/dev/ref/contrib/admin/#templates-which-may-be-overridden-per-app-or-model
>> )
>>
>>
>> Again, my feet don't touch bottom. I tried adding some code to
>> change_form.html like this ...
>>
>> {% extends "admin/change_form.html" %}
>>
>> {% block content %}{{ block.super }}
>> {% if original.ddstructure %}
>> {{ original.ddstructure | safe }}
>> {% else %}
>> No 2D structure image 
>> {% endif %}
>>
>> {% endblock %}
>>
>> This kinda worked. It comes after block.super so it displays the svg
>> image correctly but at the bottom of the page. AND the raw (or safe) code
>> also displays in the location where I really want the image.
>>
>> So close but ...
>>
>> How do I get it to display inline in the proper place?
>>
>> Many thanks for hanging in there
>>
>> Cheers
>>
>> Mike
>>
>>
>>
>> Derek
>>
>>
>> On Thursday, 3 June 2021 at 08:22:57 UTC+2 Mike Dewhirst wrote:
>>
>>> On 3/06/2021 4:00 pm, Derek wrote:
>>> > >
>>> > > E.g.
>>> > >
>>> > > class MyModel():
>>> > > svg_text = CharField()
>>> >
>>> > in my case it is ...
>>> >
>>> > class Chemical(models.Model):
>>> > ...
>>> > ddstructure = models.TextField(
>>> > null=True,
>>> > blank=True,
>>> > verbose_name="2D structure",
>>> > )
>>> >
>>>
>>> The above is unchanged.
>>>
&

Re: SVG widget for the Admin

2021-06-04 Thread Derek
Hi Mike

The SVG is not going to display as SVG in a *form* - for that you'd need a 
widget, or perhaps just let users edit the text.

Did you try displaying in the normal admin lists? This was my understanding 
of where you wanted to see it and the code snippets I posted were for that 
purpose.

If you want to see it as "read only" in the form, but shown as SVG, perhaps 
you need a custom model template 
(https://docs.djangoproject.com/en/dev/ref/contrib/admin/#templates-which-may-be-overridden-per-app-or-model)

Derek


On Thursday, 3 June 2021 at 08:22:57 UTC+2 Mike Dewhirst wrote:

> On 3/06/2021 4:00 pm, Derek wrote:
> > >
> > > E.g.
> > >
> > > class MyModel():
> > > svg_text = CharField()
> >
> > in my case it is ...
> >
> > class Chemical(models.Model):
> > ...
> > ddstructure = models.TextField(
> > null=True,
> > blank=True,
> > verbose_name="2D structure",
> > )
> >
>
> The above is unchanged.
>
> # admin
> class ChemicalAdmin(admin.ModelAdmin):
>
> def _ddstructure(self, obj):
> return mark_safe(obj.ddstructure)
> ...
> fieldsets = (
> (
> None,
> {
> "fields": (
> "ddstructure",# displays svg code
> "_ddstructure",
> ...
> }
> ),
>
> FYI it works perfectly as a column in the list display - but I don't 
> need it there, rather in the page for the chemical.
>
> This is what happens if it is included in the fieldsets "fields" roster.
>
>
> FieldError at /admin/chemical/chemical/17/change/
>
> Unknown field(s) (_ddstructure) specified for Chemical. Check 
> fields/fieldsets/exclude attributes of class ChemicalAdmin.
>
> Request Method: GET
> Request URL: http://localhost:8088/admin/chemical/chemical/17/change/
> Django Version: 3.2.3
> Exception Type: FieldError
> Exception Value: 
>
> Unknown field(s) (_ddstructure) specified for Chemical. Check 
> fields/fieldsets/exclude attributes of class ChemicalAdmin.
>
> Exception Location: 
> D:\Users\mike\envs\xxai\lib\site-packages\django\contrib\admin\options.py, 
> line 712, in get_form
> Python Executable: D:\Users\mike\envs\xxai\Scripts\python.exe
> Python Version: 3.8.3
>
>
> Cheers
>
> Mike
>
>
> > >
> > > def _the_svg(self):
> > > return """%s""" %
> > > self.svg_text
> > > _the_svg.allow_tags = True
> >
>
>
> -- 
> Signed email is an absolute defence against phishing. This email has
> been signed with my private key. If you import my public key you can
> automatically decrypt my signature and be sure it came from me. Just
> ask and I'll send it to you. Your email software can handle signing.
>
>

-- 
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/4862b67b-e5e9-40a3-b3aa-1666f4739703n%40googlegroups.com.


Re: SVG widget for the Admin

2021-06-03 Thread Derek
Hi Mike

OK, if you have more specific feedback I will try to respond.

I doubt you need a specific template as the SVG should be displayable by a 
modern browser using Django's built-in options.


On Thursday, 3 June 2021 at 01:10:07 UTC+2 Mike Dewhirst wrote:

> Derek
>
> I pretty much tried what you suggested. I dont have access to my machine 
> atm so that's all I can really say. 
>
> I looked at the link and understand the list customisation because I 
> already use it elsewhere. 
>
> It does look like I'll have to switch in my own template so I can include 
> a safe filter.
>
> Thanks again
>
> Mike
>
>
>
> --
> (Unsigned mail from my phone)
>
>
>
>  Original message 
> From: Derek  
> Date: 2/6/21 23:39 (GMT+10:00) 
> To: Django users  
> Subject: Re: SVG widget for the Admin 
>
> When you say "I tried your suggestion and had no success." what exactly 
> did you try  - i.e. what code did you use and what errors did you get?
>
> WRT "Not sure where this should live for the Admin to call it and display 
> the image." - it lives exactly as I showed it in my example; its a 
> user-defined property for the model in which the SVG text is stored.  You 
> can use it in the admin as you would the normal model fields. 
>
> There is a good example of defining and using your own derived 'field'  
> here:
>
> https://realpython.com/customize-django-admin-python/#modifying-a-change-list-using-list_display
>
> (Please note that to show HTML strings, you need to use the format_html() 
> method. Ignore mt previous reference to "allow_tags" as this is deprecated.)
>
> Derek
>
>
> On Wednesday, 2 June 2021 at 10:05:11 UTC+2 Mike Dewhirst wrote:
>
>> On 1/06/2021 11:44 pm, Derek wrote: 
>> > You haven't defined where in the admin interface you want this image 
>> > to be displayed?  A table? 
>> > 
>> > I have not tried this, but could you not create an additional field on 
>> > your model that returns the HTML-encoding needed to display the SVG? 
>>
>> Derek, thanks for responding. I tried your suggestion and had no success. 
>>
>> Where in the admin? Just among a normal roster of fields. The svg is a 
>> molecular structure and the image needs to appear for example just after 
>> the molecular formula. I collect the actual svg code via a public API on 
>> saving the record. 
>>
>> > 
>> > E.g. 
>> > 
>> > class MyModel(): 
>> > svg_text = CharField() 
>>
>> in my case it is ... 
>>
>> class chemical(models.Model): 
>> ... 
>> ddstructure = models.TextField( 
>> null=True, 
>> blank=True, 
>> verbose_name="2D structure", 
>> ) 
>>
>> > 
>> > def _the_svg(self): 
>> > return """%s""" % 
>> > self.svg_text 
>> > _the_svg.allow_tags = True 
>>
>> Not sure where this should live for the Admin to call it and display the 
>> image. 
>>
>>
>> > I am not sure about editing visually, however - I would expect that 
>> > would require a specialised widget. 
>>
>> It is read-only in all cases. 
>>
>> I was thinking a widget might be needed just for display. The svg code 
>> arrives complete with tags so really all it needs is a mechanism to 
>> persuade the admin it is safe to render as is. 
>>
>> I haven't seen such a (probably insecure) "feature" previously. I've 
>> looked through the docs but haven't found it yet. 
>>
>> Thanks again 
>>
>> Mike 
>>
>>
>> > 
>> > HTH 
>> > Derek 
>> > 
>> > 
>> > On Tuesday, 1 June 2021 at 03:28:59 UTC+2 Mike Dewhirst wrote: 
>> > 
>> > I collect the svg source for an image from a public API and store 
>> > it in 
>> > a models.TextField. I have no difficulty displaying it in a normal 
>> > view 
>> > and my own template. Nothing special, it just emerges. I don't 
>> > even need 
>> > a 'safe' filter. 
>> > 
>> > However, I really want to display such images in the Admin. At this 
>> > stage all it displays is the svg source. 
>> > 
>> > What is the correct way to make the image appear in the Admin? 
>> > 
>> > Do I need a special field inheriting from TextField? Do I need a 
>> > special 
>> > widget? Is there a way to mark admin field values as safe? 
>> > 
>> > Thanks for any hints 
&

Re: SVG widget for the Admin

2021-06-02 Thread Derek
When you say "I tried your suggestion and had no success." what exactly did 
you try  - i.e. what code did you use and what errors did you get?

WRT "Not sure where this should live for the Admin to call it and display 
the image." - it lives exactly as I showed it in my example; its a 
user-defined property for the model in which the SVG text is stored.  You 
can use it in the admin as you would the normal model fields. 

There is a good example of defining and using your own derived 'field'  
here:
https://realpython.com/customize-django-admin-python/#modifying-a-change-list-using-list_display

(Please note that to show HTML strings, you need to use the format_html() 
method. Ignore mt previous reference to "allow_tags" as this is deprecated.)

Derek


On Wednesday, 2 June 2021 at 10:05:11 UTC+2 Mike Dewhirst wrote:

> On 1/06/2021 11:44 pm, Derek wrote:
> > You haven't defined where in the admin interface you want this image 
> > to be displayed?  A table?
> >
> > I have not tried this, but could you not create an additional field on 
> > your model that returns the HTML-encoding needed to display the SVG?
>
> Derek, thanks for responding. I tried your suggestion and had no success.
>
> Where in the admin? Just among a normal roster of fields. The svg is a 
> molecular structure and the image needs to appear for example just after 
> the molecular formula. I collect the actual svg code via a public API on 
> saving the record.
>
> >
> > E.g.
> >
> > class MyModel():
> > svg_text = CharField()
>
> in my case it is ...
>
> class chemical(models.Model):
> ...
> ddstructure = models.TextField(
> null=True,
> blank=True,
> verbose_name="2D structure",
> )
>
> >
> > def _the_svg(self):
> > return """%s""" % 
> > self.svg_text
> > _the_svg.allow_tags = True
>
> Not sure where this should live for the Admin to call it and display the 
> image.
>
>
> > I am not sure about editing visually, however - I would expect that 
> > would require a specialised widget.
>
> It is read-only in all cases.
>
> I was thinking a widget might be needed just for display. The svg code 
> arrives complete with tags so really all it needs is a mechanism to 
> persuade the admin it is safe to render as is.
>
> I haven't seen such a (probably insecure) "feature" previously. I've 
> looked through the docs but haven't found it yet.
>
> Thanks again
>
> Mike
>
>
> >
> > HTH
> > Derek
> >
> >
> > On Tuesday, 1 June 2021 at 03:28:59 UTC+2 Mike Dewhirst wrote:
> >
> > I collect the svg source for an image from a public API and store
> > it in
> > a models.TextField. I have no difficulty displaying it in a normal
> > view
> > and my own template. Nothing special, it just emerges. I don't
> > even need
> > a 'safe' filter.
> >
> > However, I really want to display such images in the Admin. At this
> > stage all it displays is the svg source.
> >
> > What is the correct way to make the image appear in the Admin?
> >
> > Do I need a special field inheriting from TextField? Do I need a
> > special
> > widget? Is there a way to mark admin field values as safe?
> >
> > Thanks for any hints
> >
> > Mike
> >
> > -- 
> > Signed email is an absolute defence against phishing. This email has
> > been signed with my private key. If you import my public key you can
> > automatically decrypt my signature and be sure it came from me. Just
> > ask and I'll send it to you. Your email software can handle signing.
> >
> >
> > -- 
> > 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 
> > <mailto:django-users...@googlegroups.com>.
> > To view this discussion on the web visit 
> > 
> https://groups.google.com/d/msgid/django-users/520bf296-ec68-48ad-8fe2-f106823efac2n%40googlegroups.com
>  
> > <
> https://groups.google.com/d/msgid/django-users/520bf296-ec68-48ad-8fe2-f106823efac2n%40googlegroups.com?utm_medium=email_source=footer
> >.
>
>
> -- 
> Signed email is an absolute defence against phishing. This email has
> been signed with my private key. If you import my public key you can
> automatically decrypt my signature and be sure it came from me. Just
> ask and I'll send it to you. Your email software can handle signing.
>
>
>

-- 
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/518a9b56-de5a-46b8-8578-89bd99f20f4fn%40googlegroups.com.


Re: SVG widget for the Admin

2021-06-01 Thread Derek
You haven't defined where in the admin interface you want this image to be 
displayed?  A table?

I have not tried this, but could you not create an additional field on your 
model that returns the HTML-encoding needed to display the SVG?

E.g. 

class MyModel():
svg_text = CharField()

def _the_svg(self):
return """%s""" % self.svg_text
_the_svg.allow_tags = True

I am not sure about editing visually, however - I would expect that would 
require a specialised widget.

HTH
Derek


On Tuesday, 1 June 2021 at 03:28:59 UTC+2 Mike Dewhirst wrote:

> I collect the svg source for an image from a public API and store it in 
> a models.TextField. I have no difficulty displaying it in a normal view 
> and my own template. Nothing special, it just emerges. I don't even need 
> a 'safe' filter.
>
> However, I really want to display such images in the Admin. At this 
> stage all it displays is the svg source.
>
> What is the correct way to make the image appear in the Admin?
>
> Do I need a special field inheriting from TextField? Do I need a special 
> widget? Is there a way to mark admin field values as safe?
>
> Thanks for any hints
>
> Mike
>
> -- 
> Signed email is an absolute defence against phishing. This email has
> been signed with my private key. If you import my public key you can
> automatically decrypt my signature and be sure it came from me. Just
> ask and I'll send it to you. Your email software can handle signing.
>
>
>

-- 
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/520bf296-ec68-48ad-8fe2-f106823efac2n%40googlegroups.com.


Re: how to input list [] dynamic in python

2021-05-31 Thread Derek
This does look a programming exercise in a class...  if you ask these 
questions in future, be warned people here will probably ask to see your 
attempt at writing code first (otherwise you are not really learning to be 
a programmer).

But, OK, it seemed interesting to me,so here is one approach:

def elementswise_left_join(l1, l2):

"""https://www.w3resource.com/python-exercises/list/python-data-type-list-exercise-155.php"";
f_len = len(l1) - (len(l2) - 1)
for i in range(0, len(l2), 1):
if f_len - i > len(l1):
break
else:
l1[i] = l1[i] + l2[i]
return l1


def get_array(n):
if n == 1:
return [1,]
r = [x for x in range(1, n + 1)]
return r


curr = []
valid = True
while valid:
num = input("Enter number: ")
if num:
new = get_array(int(num))
if len(new) > len(curr):
curr = elementswise_left_join(new, curr)
else:
curr = elementswise_left_join(curr, new)
print(curr)
else:
valid = False



On Monday, 31 May 2021 at 13:34:51 UTC+2 leoa...@gmail.com wrote:

> how about if input like in below
> 1 ) input: 3 , return [1, 2, 3]
> then continue dynamic
>
> 2) input: 2, return [2, 4, 3]
>   then continue dynamic  
>
> 3) input: 6, return [3, 6, 6, 4, 5, 6]
>   then continue dynamic  
>
> 4) input: 1, return [4, 6, 6, 4, 5, 6]
>   then continue dynamic  
>
> 5) input: 1, return [5, 6, 6, 4, 5, 6]
>
> thanks
>
>
> Pada tanggal Sen, 31 Mei 2021 pukul 18.20 paidjoo indo  
> menulis:
>
>> hello i having question, because i still learn python for me, so can help 
>> me 
>> the question is
>>
>> how about if input like in below
>> 1 ) input: 3 , return [1, 2, 3]
>>
>> 2) input: 2, return [2, 4, 3]
>>
>> 3) input: 6, return [3, 6, 6, 4, 5, 6]
>>
>> 4) input: 1, return [4, 6, 6, 4, 5, 6]
>>
>> 5) input: 1, return [5, 6, 6, 4, 5, 6]
>>
>> 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/3a5ee884-4d66-4fc3-8217-64658d7f585dn%40googlegroups.com.


Re: Business logic constants

2021-05-30 Thread Derek
There are many types of constants. We have a 'utils' directory (at same 
level as 'apps') and under that 'constants' sub-directory - with different 
files for different types of constants that are generally applicable across 
all apps.  But because we have lots of client-specific constants and coding 
of their business rules, those sit under their own structure elsewhere.  
Using imports though, makes it relatively easier to reorganise over time if 
you need to.

The Django settings file is really only for constants related to starting 
up the program itself (and in our case a single flag to track who the 
client is). 

On Sunday, 30 May 2021 at 13:17:10 UTC+2 ypolo...@gmail.com wrote:

> When working with business logic implementation code and you do not want 
> use magic numbers in the code - where is the best place to put all those 
> CONSTANTS ? Django settings file ?
>
>

-- 
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/0ea0826a-e313-43f5-b65b-e488cfd194b3n%40googlegroups.com.


Re: Chrome book vs Django application development

2021-05-23 Thread Derek
Perhaps install Linux and work from there?

https://www.howtogeek.com/363331/how-to-set-up-and-use-linux-apps-on-chrome-os/

It may be that PostgreSQL is too demanding and can be avoided for 
development purposes; rather use sqlite.

It could also be worth considering to switching to cloud-based CI - replace 
Github & Jenkins with GitLab CI/CD - 
see https://dzone.com/articles/jenkins-vs-gitlab-ci-battle-of-cicd-tools

(I don't own a Chromebook but would be curious as to how well all this 
works.)

On Sunday, 23 May 2021 at 02:29:38 UTC+2 ram.mu...@gmail.com wrote:

> Hi,
>
> I'm wondering whether any one used Chrome book for development especially 
> with this software stack
>
> 1. Django
> 2. Python
> 3. Vue.js
> 4. Postgres
> 5. Nginx
> 6. Gunicorn
> 7. Github
> 8. Jenkins
>
> Best Regards,
> ~Ram
>
>
>
>

-- 
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/ad5e72a4-2c40-49cd-970d-2e9b9c381c26n%40googlegroups.com.


Re: After user click on like button page should not refresh(redirect) and update count of likes

2021-05-05 Thread Derek
You'll need to use javascript for this - have a look 
at https://data-flair.training/blogs/ajax-in-django/ for an example.

On Wednesday, 5 May 2021 at 05:30:59 UTC+2 sali...@rohteksolutions.com 
wrote:

> When user click to like a post the web page should not refresh(redirect) 
> and count of the likes should be updated.
>  How can I achieve this please help me.
>
> Here is my block of code
> ```
>href="/post_comment_like/{{j.id}}">
> aria-hidden="true"
>   style="color: gray;">
> ```
> views.py
> ```
> def post_comment_like(request, id):
> if (request.session.get('email') is None) or 
> (request.session.get('email') == ""):
> return HttpResponseRedirect("/home")
>
> email = request.session.get('email')
> qury = Comment.objects.get(id=id)
> obj_id = qury.object_id
> qury_like = Comment_like.objects.filter(email=email)
> qury_like = Comment_like.objects.filter(email=email, object_id=qury.id, 
> dislike_comment="1").first()
> if qury_like:
> qury_like.delete()
> save_form = Comment_like(email=email, 
> user_name=request.session.get('name'),
> content_type=qury.content_type,
> object_id=qury.id,
> content=qury.content,
> flag_reply=qury.flag_reply,
> flag_comment_id=qury.flag_comment_id,
> flag_level=qury.flag_level,
> like_comment='1')
> save_form.save()
> qury.like_comment = '1'
> qury.dislike_comment = '0'
> qury.save()
> # return redirect(request.META.get('HTTP_REFERER'))
> return HttpResponseRedirect(reverse('detail', args=[str(obj_id)]))
> ```
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/f44ffafe-9d01-43ac-a7ce-43286551aec4n%40googlegroups.com.


Re: Admin layout getting too bulky - what to do?

2021-05-05 Thread Derek
"I'd like to see the sidebar display links to those (currently) dumb 
headings and fetch them to the top."

As I said, you'd need to see if it possible to update Django Suit 
on-the-fly.

Alternately, you could look at making a model-specific template layout 
(e.g. https://realpython.com/customize-django-admin-python/ ) - but to make 
it generic to apply across all pages would require a significantly deeper 
level of admin know-how than I have.  Maybe there are Django admin plugin 
projects you could look at for inspiration? 

On Monday, 3 May 2021 at 16:44:26 UTC+2 Mike Dewhirst wrote:

> Derek
>
> My phone doesn't do interspersed responses well, so my apologies for top 
> posting. 
>
> The record to which I refer is any one of those in any list page.
>
> After clicking one, if that record has any 1:1, 1:n or n:m related 
> records, their *verbose_name_plural* names will be displayed as dumb 
> headings with related records appearing below with show/hide links as well 
> as an 'Add another ...' link.
>
> I'd like to see the sidebar display links to those (currently) dumb 
> headings and fetch them to the top.
>
> Hope that clarifies what I meant despite what I said :-)
>
> I'll  have a look at Django suit in the morning. Thanks for the heads up.
>
> Cheers
>
> Mike 
>
>
>
> --
> (Unsigned mail from my phone)
>
>
>
>  Original message 
> From: Derek  
> Date: 3/5/21 19:42 (GMT+10:00) 
> To: Django users  
> Subject: Re: Admin layout getting too bulky - what to do? 
>
> Re "So my need is for a fixed vertical sidebar with the same links which 
> take you to the same list pages."
>
> This is what I use Django Suit for -  it can be located at the top or side 
> and remains in place across all admin pages.  You can add your own items to 
> the menu (and these can point to non-admin pages - for example, I point to 
> a page of report URLs which is a non-standard admin page) ; I have never 
> added menu items "on the fly" so am not sure this is possible.
>
> I cannot understand your requirement statement "When that page opens for 
> the record, the sidebar of links should change to the named headings on 
> that page. When a heading is clicked the page should relocate itself so 
> that heading is at the top"  at all, sorry. Maybe a follow-up post with a 
> picture (== 1000 words)?
>
> Derek
>
>
> On Monday, 3 May 2021 at 08:57:25 UTC+2 Mike Dewhirst wrote:
>
>> OK - I've now looked at some Django Admin templating systems and they 
>> all seem to solve a different problem than the one I need to ... which 
>> is ... 
>>
>> Consider the Admin main menu seen at the /admin url after login. If you 
>> click any of the links they take you to a single page with a list of 
>> records. So my need is for a fixed vertical sidebar with the same links 
>> which take you to the same list pages. The vertical sidebar should 
>> remain unchanged and unmoved on the list page in case the user clicked 
>> the wrong link. 
>>
>> The next step is to select a record from the list. When that page opens 
>> for the record, the sidebar of links should change to the named headings 
>> on that page. When a heading is clicked the page should relocate itself 
>> so that heading is at the top. The sidebar of links should remain 
>> unchanged and unmoved in case the user wishes to relocate to a different 
>> heading. Much like the Django documentation except the sidebar should 
>> stay where it was when clicked! 
>>
>> At the moment, those headings don't have urls within the page. And the 
>> (Show/Hide) urls are all just a lone hash '#'. 
>>
>> Therefore my problem is to understand how to include heading name 
>> anchors and construct a list of urls (including 'top' and bottom') for 
>> such a sidebar. And of course to understand how to make such a sidebar 
>> in the first place. 
>>
>> Where might I begin my research? 
>>
>> Thanks 
>>
>> Mike 
>>
>>
>> On 2/05/2021 5:26 pm, Mike Dewhirst wrote: 
>> > My project has a central table with many 1:n and n:m sub-tables. I 
>> > mean lots of them. It takes forever to keep scrolling up and down the 
>> > page to find the section of interest and then maybe scroll through 
>> > some records in that section before clicking (SHOW) to reveal data. 
>> > 
>> > Is there a way I can do a sidebar of links which take the user to 
>> > specific sections? 
>> > 
>> > I have had a look at the contrib layout and it doesn't appear obvious 
>> > what to do. Especially since they don't pay 

Re: Admin layout getting too bulky - what to do?

2021-05-03 Thread Derek
Re "So my need is for a fixed vertical sidebar with the same links which 
take you to the same list pages."

This is what I use Django Suit for -  it can be located at the top or side 
and remains in place across all admin pages.  You can add your own items to 
the menu (and these can point to non-admin pages - for example, I point to 
a page of report URLs which is a non-standard admin page) ; I have never 
added menu items "on the fly" so am not sure this is possible.

I cannot understand your requirement statement "When that page opens for 
the record, the sidebar of links should change to the named headings on 
that page. When a heading is clicked the page should relocate itself so 
that heading is at the top"  at all, sorry. Maybe a follow-up post with a 
picture (== 1000 words)?

Derek


On Monday, 3 May 2021 at 08:57:25 UTC+2 Mike Dewhirst wrote:

> OK - I've now looked at some Django Admin templating systems and they 
> all seem to solve a different problem than the one I need to ... which 
> is ...
>
> Consider the Admin main menu seen at the /admin url after login. If you 
> click any of the links they take you to a single page with a list of 
> records. So my need is for a fixed vertical sidebar with the same links 
> which take you to the same list pages. The vertical sidebar should 
> remain unchanged and unmoved on the list page in case the user clicked 
> the wrong link.
>
> The next step is to select a record from the list. When that page opens 
> for the record, the sidebar of links should change to the named headings 
> on that page. When a heading is clicked the page should relocate itself 
> so that heading is at the top. The sidebar of links should remain 
> unchanged and unmoved in case the user wishes to relocate to a different 
> heading. Much like the Django documentation except the sidebar should 
> stay where it was when clicked!
>
> At the moment, those headings don't have urls within the page. And the 
> (Show/Hide) urls are all just a lone hash '#'.
>
> Therefore my problem is to understand how to include heading name 
> anchors and construct a list of urls (including 'top' and bottom') for 
> such a sidebar. And of course to understand how to make such a sidebar 
> in the first place.
>
> Where might I begin my research?
>
> Thanks
>
> Mike
>
>
> On 2/05/2021 5:26 pm, Mike Dewhirst wrote:
> > My project has a central table with many 1:n and n:m sub-tables. I 
> > mean lots of them. It takes forever to keep scrolling up and down the 
> > page to find the section of interest and then maybe scroll through 
> > some records in that section before clicking (SHOW) to reveal data.
> >
> > Is there a way I can do a sidebar of links which take the user to 
> > specific sections?
> >
> > I have had a look at the contrib layout and it doesn't appear obvious 
> > what to do. Especially since they don't pay me enough to play with js ;-)
> >
> > Has this been solved before?
> >
> > Thanks for any hints
> >
> > Cheers
> >
> > Mike
> >
>
>
> -- 
> Signed email is an absolute defence against phishing. This email has
> been signed with my private key. If you import my public key you can
> automatically decrypt my signature and be sure it came from me. Just
> ask and I'll send it to you. Your email software can handle signing.
>
>
>

-- 
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/ec2ed88b-564c-477a-8ebe-067c2d975bf7n%40googlegroups.com.


Re: Loading csv data in database

2021-04-30 Thread Derek
Someone has an example of doing just this:

https://arshovon.com/blog/django-custom-command/


On Thursday, 29 April 2021 at 19:39:36 UTC+2 Ryan Nowakowski wrote:

> Typically you would write a custom management command for this kind of 
> thing:
>
> https://docs.djangoproject.com/en/3.2/howto/custom-management-commands/
>
>
> On April 29, 2021 11:05:29 AM CDT, 'Muhammad Asim Khaskheli' via Django 
> users  wrote:
>>
>>
>> Hi,
>>
>> I wanted to ask how to load CSV data into the model. What steps do we 
>> have to follow?
>>
>> I have made this function but how exactly to run this code because, 
>> python manage.py load data won't work. 
>>
>> def import_data():
>> with open('sample-dataset.csv') as f:
>> reader = csv.reader(f)
>> for row in reader:
>> if row[0] != 'user_id':
>> _, created = Funnel.objects.get_or_create(
>> user_id=row[0],
>> event=row[1],
>> timestamp=row[2],
>> session_id=row[3]
>> )
>>
>> Now, how to run this script?
>>
>>
>>

-- 
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/137aee79-07e6-40e1-badd-671ae3b0c87cn%40googlegroups.com.


Re: How to save a result of multiplication

2021-04-26 Thread Derek
I think you have used the wrong name - "saveit" instead of "save" - also 
have a look at the example in the docs:
https://docs.djangoproject.com/en/3.2/topics/db/models/#overriding-predefined-model-methods
and see which parameters are needed for it.

On Saturday, 24 April 2021 at 20:50:15 UTC+2 encinas...@gmail.com wrote:

> Hi everyone i build a web application in Django 3.1.7 and i try to do the 
> next opeation(multiplication).
>
> in my models a have:
> class Articles(models.Model):
>  quantity = models.PositiveIntegerField()
> cost_buy = models.DecimalField(max_digits=10, decimal_places=2)
> total_todo = models.DecimalField(max_digits=10, decimal_places=3)
>
> @property
> def total_valores(self):
>  return (self.cost_buy*self.quantity)
>
> def saveit(self):
> self.total_todo = self.total_valores
> super (Articles, self).save()
> __
>
> so, I was tried with this functions , but it's doesn't save anything
>
> would you give me some recomendations.
>
> Thank you very much in advance and I remain at your service regards 
>

-- 
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/fb9b6d0f-18b6-4771-b812-a0644cb03806n%40googlegroups.com.


Re: Validate group of fields

2021-04-26 Thread Derek
The docs cover this use case:

https://docs.djangoproject.com/en/3.2/ref/forms/validation/#cleaning-and-validating-fields-that-depend-on-each-other

On Saturday, 24 April 2021 at 19:57:50 UTC+2 robert...@gmail.com wrote:

>
>
> Hello guys!
>
> I've 3 fields, but I need validate it as a group, Ej:
>
> adults = forms.IntegerField(initial=0)
> kids = forms.IntegerField(initial=0)
> students = forms.IntegerField(initial=0)
>
> The Idea is to validate it as a group, not sure if that makes sense or if 
> I need custom validation for that fields
>
> 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/9f3c6f53-7afc-428c-80be-86d06a7f02c1n%40googlegroups.com.


Re: how to get only the 'title' attribute value from following data in django

2021-04-23 Thread Derek
I'd use:

querye = Product.objects.filter(id=sell_id).values('title')
title = querye[0]['title']  # get the title for the first Product

But if you're sure there is one (and only one) product matching the 
'sell_id', you can use:

querye = Product.objects.get(id=sell_id)
title = querye.title

HTH

On Thursday, 22 April 2021 at 13:53:18 UTC+2 bhathiy...@gmail.com wrote:

>
> This is the views.py I want to get 'title' attribute from the serialize 
> data
>
> views.py
> class CalculatView(views.APIView):
> query = CartProduct.objects.latest('id') 
>  serializer = CartProductSerializer(query) 
>  choose_product = serializer.data.get('product') 
>  [sell_id] = choose_product 
>  querye = Product.objects.filter(id = sell_id) 
>  serializere = ProductSerializers(querye, many=True) 
>  choosee = serializere.data 
>
>   print(choosee)
>
> Output : 
>
> [OrderedDict([('id', 2), ('title', 'Frock'), ('date', '2021-04-22'), 
> ('image', '/media/products/kids2.jpg'), ('marcket_price', 1.2), 
> ('selling_price', 1.2), ('description', 'a'), 
> ('category', OrderedDict([('id', 2), ('title', 'Fashion'), ('date', 
> '2021-04-22')])), ('seller', OrderedDict([('id', 2), ('seller_name', 'CIB - 
> Piliyandala'), ('lat', 6.8018), ('lng', 79.9227), ('date', 
> '2021-04-22')]))])]
>
>
>

-- 
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/ad89068d-d98c-4f08-93da-d172c789e889n%40googlegroups.com.


Re: Unique and null

2021-04-07 Thread Derek
Are you using MySQL?

https://stackoverflow.com/questions/371/does-mysql-ignore-null-values-on-unique-constraints


On Wednesday, 7 April 2021 at 08:07:35 UTC+2 Mike Dewhirst wrote:

> I have just made a CharField unique and Django detects duplicates nicely 
> but seems to ignore multiple instances where the field value is null.
>
> arn = models.CharField(
> max_length=MEDIUM,
> unique=True,
> null=True,
> blank=True,
> )
>
> Is this correct behaviour?
>
> Thanks
>
> Mike
>
>
>
> -- 
> Signed email is an absolute defence against phishing. This email has
> been signed with my private key. If you import my public key you can
> automatically decrypt my signature and be sure it came from me. Just
> ask and I'll send it to you. Your email software can handle signing.
>
>

-- 
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/efd40f22-50d8-4250-9738-95d2152e68ecn%40googlegroups.com.


Re: License management system Refrence

2021-04-06 Thread Derek
You seem to be mixing up different aspects here.

1. Trying to control access to a web app through device-level details is 
*not* a viable option. The whole point of web apps (as opposed to ones 
installed on a user's machine under a specific OS) is that the machine they 
are running on is mostly irrelevant.

2. For a demo, you are better off handing out a default user-name and 
password - and when the demo period has expired, then simply deactivating 
that user.

3. Assuming that the software is now running & the client has purchased 
usage for N users; then an app such as this one 
(https://pypi.org/project/django-limits/) can ensure they do not exceed 
their allowed number.

4. For generation of an ID to help track products (I assume you mean like 
goods that are being sold), have a look at the UUIDField 
- https://www.geeksforgeeks.org/uuidfield-django-models/

HTH
Derek

On Tuesday, 6 April 2021 at 08:50:51 UTC+2 bikash...@gmail.com wrote:

> Can any one provide me reference regarding license (Serial Key) server 
> system  in django,
> where ,
> we can generate unique serial key for products,
> we can validate user subscription,
> Clients can run demo (limited features),
> and with that serial key users can run with limited device,(Device lock)
>
> Hopefully can I get some reference , Pease provide me some materials in 
> django.
>

-- 
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/5f2858da-48d9-4a11-ba3b-3d8c5e3c7e84n%40googlegroups.com.


Re: Regarding auto-generating a map with measurements

2021-04-06 Thread Derek
We have done something similar, but for a rectangular layout you may be 
able to also use a simple HTML table, or a series of nested "div"s (with 
appropriate styling).  

On Tuesday, 6 April 2021 at 01:42:17 UTC+2 sammym...@gmail.com wrote:

> This was of great help, thanks!
>
>
> On Mon, Apr 5, 2021, 22:52 Ryan Nowakowski  wrote:
>
>> No prob.  A trick that I use sometimes is to create a sample SVG manually
>> with Inkscape.  Then I modify it with Inkscape to manually "add" whatever
>> I'm thinking about adding automatically.  Finally I can diff the
>> original file I created with Inkscape and with modified file to find out
>> what values I need to change in my SVG Django template.
>>
>> On Sun, Apr 04, 2021 at 08:05:27AM +0530, Srijita Mallick wrote:
>> > Actually that's a great idea, thanks :). We can create a large rectangle
>> > and fit in small SVG beds using loop as per measurements.
>> > 
>> > Thanks again!
>> > 
>> > On Sun, Apr 4, 2021, 07:50 Ryan Nowakowski  wrote:
>> > 
>> > > Perhaps use SVG?
>> > >
>> > > On April 3, 2021 12:00:12 AM CDT, Srijita Mallick <
>> sammym...@gmail.com>
>> > > wrote:
>> > >>
>> > >> Hello all!
>> > >> I'm doing a project where provided length and breadth of a land, I 
>> have
>> > >> to auto-generate a map with no. of flower beds (length of them 
>> provided
>> > >> too) in it like the image I have attached below. How can I go about 
>> it?
>> > >> Any help is much appreciated.
>> > >>
>> > >> Thanks and regards,
>> > >> Srijita
>> > >>
>> > >> --
>> > > 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 view this discussion on the web visit
>> > > 
>> https://groups.google.com/d/msgid/django-users/E1535D26-6A34-4879-8FBF-07E9A8A8427B%40fattuba.com
>> > > <
>> https://groups.google.com/d/msgid/django-users/E1535D26-6A34-4879-8FBF-07E9A8A8427B%40fattuba.com?utm_medium=email_source=footer
>> >
>> > > .
>> > >
>> > 
>> > -- 
>> > You received this message because you are subscribed to the Google 
>> Groups "Django users" group.
>> > To unsubscribe from this group and stop receiving emails from it, send 
>> an email to django-users...@googlegroups.com.
>> > To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/CAEq3HBT%3DiKvToxAWRLC%2Bi0v8rpzsSRC13gFgfWwHUgQfPMn8sQ%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...@googlegroups.com.
>>
> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/20210405172217.GB15054%40fattuba.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/87400171-d41a-4687-8ac0-4fb241621074n%40googlegroups.com.


Re: Deploy Django website internally within company network

2021-04-06 Thread Derek
Our IT dept. will typically set up a virtual machine, with you as admin, 
into which you can install your own software. Provided it will not be 
visible outside the company's firewall, this is usually not an issue for 
them.

On Thursday, 1 April 2021 at 15:14:13 UTC+2 Ryan Nowakowski wrote:

> I typically develop the website and also handle deployment. I've done this 
> in a couple of ways. I get the IT department to give me a virtual machine 
> or an AWS account so I can spin up my own EC2 instance. Then I get them to 
> assign a DNS name to the server.
>
>
> On March 31, 2021 6:11:11 PM CDT, tristant  wrote:
>>
>> So I am trying to propose building an internal website site at work with 
>> Django. But I have no idea what is needed from an IT perspective. I know 
>> how to deploy one on the internet through Heroku or such. But what are the 
>> steps/resource requirements if I was to deploy within an intranet? The IT 
>> department has not done this with Django before ( although they have done 
>> so with other framework such as Angular, etc).
>>
>> If someone could give me some pointers on this process.
>>
>> 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/6e1b7d06-392a-4c55-ab72-8a5d3a693bb3n%40googlegroups.com.


Re: How to get only month name and total

2021-04-06 Thread Derek
Have a look at the last answer in this SO question:
https://stackoverflow.com/questions/8414584/how-to-get-month-of-a-date-in-a-django-queryset/43505881


On Sunday, 4 April 2021 at 07:32:41 UTC+2 azharul.t...@gmail.com wrote:

> Hello ,
> I am trying to get only month name and count number from *QuerySet [{'month': 
> datetime.datetime(2021, 3, 1, 0, 0, tzinfo= +06+6:00:00 STD>), 'count': 2 }]*
>
> As here have (2021, 3, 1,0,0) but I want only 3 or March. and count 2
>
> How can i view the month and count only, please?
>
> 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/f47b9d96-f10e-4225-9abd-d59e9e6f70bdn%40googlegroups.com.


Re: Django asychronous for millions of users

2021-03-31 Thread Derek
I agree with Lars. You have said very little about your actual situation; 
my concern would be that if someone was appointed to develop a web-based 
system that was expected to scale that big and that fast I would expect (in 
fact, if I was the project funder I would *demand*) that you already have a 
number of years experience developing, deploying and maintaining such 
systems - preferably in more than one domain.  There are very smart and 
knowledgeable people on this mailing list - you may want to consider hiring 
or partnering with someone like that who can offer you this capability.

On Wednesday, 31 March 2021 at 14:46:25 UTC+2 lie...@punkt.de wrote:

> Sorry for having been so blunt, but your mail looked to me like some 
> random person asking for how to simply implement something with $framework.
>
> But my remarks had a lot of expirience in them. If you are still not 
> decided on a language or framework then I would suggest you choose the 
> language you are most familiar with and the framework, that offers what you 
> expect from it. Before deciding though you should  also have a look at the 
> integration of caching, because you will definetely need something like 
> e.g. redis and maybe varnish. Additionally you should think about which 
> database you want to use and if this can do clustering. 
>
> Django can do all of this and might be the right choice for you, but have 
> a look at how Django "thinks" and decide, if this is a way that you could 
> familiarize yourself well with.
>
> As often in IT there are now real "right" choices, only choices that will 
> be right for you and your usecase.
>
> Cheers
>
> Lars
> Am 31.03.21 um 01:28 schrieb Josh moten:
>
> I am trying to implement the right infrastructure, so that I can be able 
> to support all the users. I am in no way trying to deceive anyone. I am 
> asking because I truly want to make the right decisions from the beginning, 
> so that it will be cost effective. I am thinking of using AWS elastic band, 
> so that proper load balancing will be in place. I am also looking up 
> cacheing as well
>
> Sent from my iPhone
>
> On Mar 30, 2021, at 7:13 PM, Lars Liedtke  wrote:
>
>  
>
> Hello Josh,
>
> somehow this sounds a bit sketchy to me. Could you please extend your 
> request to your plans to setup such a system. This is not simply done with 
> choosing "the right"  library or package. This has to be a quite elaborate 
> system with multiple kinds of Software, like caches as redis and/or 
> elasticsearch, most propably load balancers and multiple application 
> servers (which could be run with django). But simply sending a question 
> like you did will not solve the prpably appearing problems you'll be 
> facing, if you really will that many users.
>
> Cheers
>
> Lars
> Am 30.03.21 um 13:32 schrieb Josh moten:
>
> I am creating an auction that will be hosting millions to possibly 
> billions of users so I am trying to figure out which would be the best 
> library to use for scalability at a rapid pace. I am positive to reach a 
> million users in four months. What is the best library and/or package to us 
> for over 100k+ users per second? -- 
> 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 view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/b0ed59a5-5892-4a0e-b159-adc89476da78n%40googlegroups.com
>  
> 
> .
>
> -- 
> ---punkt.de GmbH
> Lars Liedtke
> .infrastructure
>
> Kaiserallee 13a   
> 76133 Karlsruhe
>
> Tel. +49 721 9109 500 
> <+49%20721%209109500>https://infrastructure.punkt.dein...@punkt.de
>
> AG Mannheim 108285
> Geschäftsführer: Jürgen Egeling, Daniel Lienert, Fabian Stein
>
> -- 
> You received this message because you are subscribed to a topic in the 
> Google Groups "Django users" group.
> To unsubscribe from this topic, visit 
> https://groups.google.com/d/topic/django-users/7XmCZgz3XzI/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to 
> django-users...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/b93ddf40-0c57-732c-36af-c53728bb7cd4%40punkt.de
>  
> 
> .
>
> -- 
> 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 view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/10F9EE9C-EC21-4BF3-9C42-490D95940A1A%40gmail.com
>  
> 

Django reverse lookup fails during unit testing

2021-03-16 Thread Derek
Hi

When I open the Django shell (python manage.py shell) and test a reverse
URL:

>>> from django.urls import reverse
>>> reverse('admin:locales_site_changelist')
'/admin/locales/site/'

then it works as expected.

However, when I try and use the same lookup string via a unit test:

from django.test import TestCase
from core.models import CustomUser as User

class TestCaseSimple(TestCase):

def setUp(self):
User.objects.create_superuser(
email='t...@example.com',
password='password')
self.login = self.client.login(
email='t...@example.com',
password='password')
print('Login successful? ', self.login)  # True
url = reverse('admin:locales_site_changelist')


I get this error:

E   django.urls.exceptions.NoReverseMatch: Reverse for
'locales_site_changelist' not found. 'locales_site_changelist' is not a
valid view function or pattern name.


Is there some simple reason why reverse lookup does not work when testing?
(I actually need to use it in a client post request.)

Thanks
Derek

-- 
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/CAF1Wu3NmqC%2BqWK9v%3DNXa%3DOaLc2N3p1dkZ40r1n7gXuCk1gDaQQ%40mail.gmail.com.


Re: Django vs Spring decision

2021-03-02 Thread Derek
You''ll probably not get a unbiased opinion. Devs who work with Java as 
their primary language are going to pick Spring; and the opposite in the 
case of Python.

If you already have much Java experience and don't want to start learning 
Python, then rather go on with Spring.

Some comments over at 
Reddit: 
https://www.reddit.com/r/django/comments/d8dbx3/django_vs_spring_for_backend_development/

P.S. Python is not an "upcoming" language - its been around longer than 
Java 
(https://en.wikipedia.org/wiki/Timeline_of_programming_languages#1990s) and 
has a substantial and well-developed ecosystem. Its bigger use is 
(probably) in data science and the wider science community.  If you're 
planning to develop "pure" enterprise business systems, you may be better 
off staying with Java.


On Tuesday, 2 March 2021 at 02:16:50 UTC+2 Jan-Marten de Jong wrote:

> Dear Django users,
>
> I am in the process of deciding the architecture of a new Web application 
> and I am considering Django or Spring.  
>
> Would appreciate some feedback on why Django would be a better choice than 
> the Spring Framework. I had quite some experience with JAVA but at the 
> Universities they all start with Phyton nowadays so that seems to be an 
> upcoing language and Django seems to be one of the most popular Frameworks 
> for Phython. 
>
> Looking forward to your support in making theis very important decision.  
>
> Best regards, Jan Marten
>
>

-- 
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/eb4386f0-08d6-4711-b5c3-c49a59ec6ad4n%40googlegroups.com.


Re: Show FK as input instead of drop down in admin

2021-01-31 Thread Derek
Another option if you want to show actual data, but only a portion, is to 
use an incremental lookup via an app 
such https://django-autocomplete-light.readthedocs.io/en/master/ - this 
works in the Admin as well.

On Saturday, 30 January 2021 at 20:58:00 UTC+2 Ryan Nowakowski wrote:

> On Wed, Jan 27, 2021 at 05:33:10AM -0800, Kevin Olbrich wrote:
> > Is it possible to disable fetching of related models for admin pages?
> > I have a field that links to a table containing more than 1M rows which 
> > django tries to fetch and build the drop down. For my purpose, it is 
> > sufficient if it is a simple input containing the id instead.
> > 
> > How can I accomplish this?
>
> Yes, raw_id_fields is specifically designed for this:
>
>
> https://docs.djangoproject.com/en/3.1/ref/contrib/admin/#django.contrib.admin.ModelAdmin.raw_id_fields
>

-- 
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/8db9a0dd-336b-451c-85ac-f3fccbddf455n%40googlegroups.com.


Re: How can I segment a roads?

2021-01-06 Thread Derek
This is a spatial query problem, not a Django one.

Suggestion: use PostgreSQL and PostGIS and look at this:
https://gis.stackexchange.com/questions/107277/getting-points-along-line-at-defined-distance-using-postgis/203551

HTH
Derek

On Tuesday, 5 January 2021 at 16:12:59 UTC+2 jfa...@inerza.com wrote:

> Hi everyone, 
>
> I'm a new in django and python and i have a problem .I would like to know 
> how I can segment a road by kilometer points . 
>
> Any help is welcome. 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/81f8616d-47d4-4693-9808-ef26fccd0c04n%40googlegroups.com.


Re: Handle timeseries, how to model ?

2020-12-14 Thread Derek
Hi

I am not sure about the links with Django, but we have found that 
TimescaleDB extension for Postgresql is a very powerful tool for managing 
and extracting analytics from  timeseries data.  Some further reading to 
see if this fits your use case:

https://stackoverflow.com/questions/25212009/django-postgres-large-time-series

https://medium.com/smart-digital-garden/timescaledb-and-django-5f2640b28ef1

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

https://docs.timescale.com/latest/using-timescaledb

Derek

On Sunday, 13 December 2020 at 18:35:58 UTC+2 Franck DG wrote:

> Hello,
> I am looking for best practices in managing the registration of 
> timeseries. I cannot find a satisfactory model for Django. The problem is 
> to model a driving simulator made up of a steering wheel, brake pedal, 
> clutch, gear lever, ... Following a session, the machine provides a file 
> with the times when the elements were used. Ex: the brake pedal was used at 
> 30, 35, 50, 300 sec ... First gear increased to 5, 60, 300 sec ... There 
> are several users, several machines and a user can do one or more sessions 
> per day on any machine. All this must be recorded - a posteriori therefore 
> - in a database in order to then use the data. Counting of events between 2 
> times, frequencies, evolution between sessions, ... I can't find the most 
> efficient way to model this into objects. If anyone can help me that would 
> be great, 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/4245f742-8acd-4cd5-a113-a047ee267814n%40googlegroups.com.


Re: I cannot output the value of the foreign key via jsonresponse serealize

2020-12-07 Thread Derek
You may want to try some of the approaches given in this StackOverflow:
https://stackoverflow.com/questions/15453072/django-serializers-to-json-custom-json-output-format


On Sunday, 6 December 2020 at 19:02:31 UTC+2 wwran...@gmail.com wrote:

> Hi mates,
>
> I want to get json serialized the name of the products instead of the id 
> ones. I tried to add natural_keys method on the parent model with no luck.
>
> I can receive the json data good but in this way:
>
> [{"model": "ocompra.compradetail", "pk": 1, "fields": {"producto": 238, 
> "precio": "620.00", "cantidad": 1}}, {"model": "ocompra.compradetail", 
> "pk": 2, "fields": {"producto": 17, "precio": "65.00", "cantidad": 2}}]
>
> Any suggestions will be much appreciated!
>
> Thanks,
>
> *views.py*
>
> def detalle(request):
> template_name = "ocompra/compra_ok.html"  
> contexto={}
> data={}if request.method=="GET":  
> cat = CompraDetail.objects.all().order_by("codigo")  
> contexto={"obj":cat}  if request.method=="POST":  
> codigos=request.POST.getlist("codigos[]")#Codigo/s de la Orden de Compra
> codigos= [int(x) for x in codigos]#Convierte la lista en integer
> items_detalle = 
> CompraDetail.objects.filter(compra__in=codigos).select_related('producto')
> for item in items_detalle:
> print(item.producto.nombre, item.cantidad, item.precio, item.subtotal)
> #data['success'] = True
> #print (data)
> return JsonResponse(serializers.serialize('json', 
> items_detalle,fields=('producto', 'cantidad','precio'), 
> use_natural_foreign_keys=True), safe=False)
> #return JsonResponse(data)return render(request,template_name,contexto)
>
> *models.py*
>
> from django.db import modelsfrom django.utils.timezone import datetimefrom 
> articulos.models import Articulos
> # Create your models here.class CompraHead(models.Model):
> numero=models.AutoField(primary_key=True)
> cliente= models.CharField(max_length=200,default="Consumidor Final")
> direccion=models.CharField(max_length=100,null=True,blank=True)
> telefono=models.CharField(max_length=50,null=True,blank=True)
> fecha=models.DateField(default=datetime.now)
> observaciones=models.CharField(max_length=400)
> subtotal=models.DecimalField(default=0.00,max_digits=9,decimal_places=2)
> descuento=models.IntegerField(default=0.0)
> total=models.DecimalField(default=0.00,max_digits=9,decimal_places=2)
> class CompraDetail(models.Model):
> compra=models.ForeignKey(CompraHead,on_delete=models.CASCADE)
> producto=models.ForeignKey(Articulos,on_delete=models.CASCADE)
> precio= models.DecimalField(max_digits=10,decimal_places=2)
> cantidad=models.IntegerField(default=0)
> subtotal=models.DecimalField(default=0.00,max_digits=9,decimal_places=2)
> def natural_key(self):
> return (self.producto.nombre)
>
> *js*
>
>var token = '{{csrf_token}}';  
>   var data = JSON.stringify({"codigos":codigos});  
>   data = {"codigos[]":codigos};  
>   console.log(data);  
>   $.ajax({  
>headers: { "X-CSRFToken": token },  
>"url": '/ocompra/detalle/',
>"type": "POST",  
>"dataType": "json",
>data: data,  
>success: function(data){
> // if(data['success']){ 
>   //location.reload(true);
> // alert(data)
> //   alert("Se actualizo correctamente.");
> //}
> alert(data)
> var obj = JSON.parse(data);
> for (i in obj)
>   alert('Producto: '+obj[i].fields.producto +'\n' + 'Cantidad: '+ 
> obj[i].fields.cantidad +'\n' + 'Precio: '+obj[i].fields.precio )
>   
>},  
>error: function(a,b,c){  
> alert(c); 
>} 
>   });
> });
>
>

-- 
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/d41f0178-1e94-4c36-b0bc-807bd981e974n%40googlegroups.com.


Re: Can't create custom user model

2020-11-24 Thread Derek
And this: https://stackoverflow.com/help/minimal-reproducible-example 

On Monday, 23 November 2020 at 15:59:50 UTC+2 Kasper Laudrup wrote:

> On 11/23/20 9:05 AM, Charles Freeman wrote:
> > Hey everyone I can't create a custom user model. Every time I try to 
> > create super user I end up with an error message saying username is not 
> > present pls help me thanks
> > 
>
> https://stackoverflow.com/help/how-to-ask
>

-- 
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/3ef26f31-3a30-40c2-b131-169c0b7d67f6n%40googlegroups.com.


Re: Need help about display machine state?

2020-11-22 Thread Derek
I am not sure the Django mailing list is the best place to get advice on 
Flask?

I did have a quick look - my advice would be to create a Docker deployment 
(ideally with a pre-built image on DockerHub) to allow quick/fast testing.

On Sunday, 22 November 2020 at 02:43:38 UTC+2 graves@gmail.com wrote:

> I built a display machine state using Python3 with Flask. 
> It can monitoring indicators: CPU, Memory, Disk usage, LoadAVG, Boot time. 
> Would anyone can give some advices? Thanks~
> Flask State Github 
>

-- 
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/da4b14f7-a3c9-411a-873e-803654a4968dn%40googlegroups.com.


Re: Integrating GeoDjango with Esri API

2020-11-22 Thread Derek
Some other (possibly useful) links are:

* https://www.youtube.com/watch?v=1-7KUHLTqjs - edit data with QGIS instead 
of GeoDjango
* 
https://stackoverflow.com/questions/19160349/geodjango-geoserver-openlayers-for-dynamic-mapping
 
- replace "geosever" with "arcmap" and the same principles apply
* 
https://desktop.arcgis.com/en/arcmap/latest/extensions/production-mapping/data-editing-with-wfs-services.htm
 
- ESRI notes on using WFS to edit data

On Friday, 20 November 2020 at 23:50:53 UTC+2 Rodrigo Culagovski wrote:

> Not looking for a general intro to geodjango, but rather what I asked. 
> Thanks anyway.
>
> Saludos,
>   *Rodrigo Culagovski*
> Director
> +569 7667 0402 <+56%209%207667%200402>
> H98R+8C Santiago
>
>
> On Fri, 20 Nov 2020 at 17:55, Dhruvil Shah  wrote:
>
>> I don't think. so, it's basic project on how to use it and also find 
>> distance from your current location to what u write in text box. 
>>
>> On Sat, 21 Nov 2020, 01:58 Rodrigo Culagovski,  wrote:
>>
>>> Does it connect to ESRI services? I can't find any reference to that in 
>>> the video, and that's what I specifically need.
>>>
>>> Saludos,
>>>   *Rodrigo Culagovski*
>>> Director
>>> +569 7667 0402 <+56%209%207667%200402>
>>> H98R+8C Santiago
>>>
>>>
>>>
>>> On Fri, 20 Nov 2020 at 15:43, Dhruvil Shah  wrote:
>>>
 You can follow this YouTuber he has made a project on GeoDjango.

 https://youtu.be/_KIMevaubfQ


 On Fri, 20 Nov 2020, 18:29 Rodrigo Cea,  wrote:

> I'm developing a mapping website. I will be consuming map layers from 
> ESRI Online. I see they have a fairly sophisticated Python API. The site 
> will be django based. I wonder how easy it would be to use GeoDjango for 
> local storage and editing of geographical  data as well as other, not 
> geolocated info, and using the ESRI api to sync it to ESRI's servers and 
> generate maps?
>
> Using ESRI maps and interacting with other ESRI based sites is a 
> client requirement, and non-negotiable.
>
> -- 
> 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 view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/1a346478-d46a-43d7-9621-3a1859133774n%40googlegroups.com
>  
> 
> .
>
 -- 
 You received this message because you are subscribed to a topic in the 
 Google Groups "Django users" group.
 To unsubscribe from this topic, visit 
 https://groups.google.com/d/topic/django-users/W4ps2dL4er0/unsubscribe.
 To unsubscribe from this group and all its topics, send an email to 
 django-users...@googlegroups.com.
 To view this discussion on the web visit 
 https://groups.google.com/d/msgid/django-users/CADsP_izDws3Msb0uRdvkt1zi0FFPvKN8h8A8RHnE_PfXbBq_MQ%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...@googlegroups.com.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/django-users/CALU%3DqNN3o9ojR5AuVrp%3DoAFpOUkS2%2Bh%2B9get_3%2B2U54Qkpk2Ug%40mail.gmail.com
>>>  
>>> 
>>> .
>>>
>> -- 
>> You received this message because you are subscribed to a topic in the 
>> Google Groups "Django users" group.
>> To unsubscribe from this topic, visit 
>> https://groups.google.com/d/topic/django-users/W4ps2dL4er0/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to 
>> django-users...@googlegroups.com.
>>
> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/CADsP_iy%2BX3Ye08yVR22PaFoRNv-QL%2BfegBr9ieAZkWQWCWD67Q%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/7d418d79-cbcc-4d08-9930-0efaf4f1201cn%40googlegroups.com.


Using smart_selects in the admin for a ChainedManyToMany?

2020-11-18 Thread Derek
Looking for some help, if possible

Working Django with 1.11.x and Django smart_selects 1.5.x

from smart_selects.db_fields import ChainedManyToManyField

class Project(Model):
"""Project is a holder for a group of activities carried out as
sub-projects.
"""
id = AutoField(primary_key=True)
name = CharField(unique=True)
description = CharField()


class Milestone(Model):
"""Milestone is a time-based goal for a Project.
"""
id = AutoField(primary_key=True)
project = ForeignKey(Project)
description = TextField()
planned_year = PositiveIntegerField()
planned_quarter()


class SubProject(Model):
"""SubProject is an activity carried out as part of a single Project.
"""
id = AutoField(primary_key=True)
project = ForeignKey(Project)
code = CharField(unique=True)
milestones = ChainedManyToManyField(
Milestone,
blank=True,
horizontal=True,
chained_field="project",
chained_model_field="milestones")


However, the admin form for SubProject simply shows the usual admin
multi-select box (i.e. just a long list of unfiltered milestones).

What needs to change in the above code to create a working smart_selects
version?

Thanks
Derek

-- 
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/CAF1Wu3OK%2BgjaScANCO%3DxC4xi%2BT-e9iaaZqfKtzPpz7jhy6Ai6Q%40mail.gmail.com.


Re: How to print sequence number in python

2020-11-15 Thread Derek
You can also use range;

>>> for i in range(0, 5):
... print(i + 1)
... 
1
2
3
4
5
>>>

or in reverse:

>>> for i in range(5, 0, -1):
... print(i)
... 
5
4
3
2
1
>>> 

On Saturday, 14 November 2020 at 21:26:04 UTC+2 vicker...@gmail.com wrote:

> Python has the enumerate function for these situations.
>
> for i, item in enumerate(items):
>  #your print statement here
>
> 'i' will give you the index of the list/iterable, and item will give you 
> the item.
>
> On Sat, 14 Nov 2020 at 11:57, paidjoo indo  wrote:
>
>> Hello I'm newbie in python, I'm learning looping in python, how to print 
>> like in bellow;
>> Input:5
>> 12345 
>> 2.  4
>> 3   3
>> 4   2
>> 54321
>>  Thanks guys
>>
>> -- 
>> 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 view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/CAO%3D2VJmeOF5SyMZUFox_hHivTr%3DE%3Dnekj_n7FLOYjGOkPHQrbA%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/281ee4c1-23bb-4eb2-a8d3-a9bc1a13e078n%40googlegroups.com.


Re: Numeric field widget with built-in units

2020-11-13 Thread Derek
Django Suit uses an "enclosed" widget - 
https://django-suit.readthedocs.io/en/develop/widgets.html#enclosedinput ; 
see also https://getbootstrap.com/docs/4.5/components/input-group/


On Friday, 13 November 2020 at 05:11:24 UTC+2 Mike Dewhirst wrote:

> Does anyone know of a number field widget with a units string?
>
> For example ...
>
> +-+ Maximum concentration: | 25.0 | % +-+
>
> Thanks
>
> Mike
>
>

-- 
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/87deb1ec-b7f5-44dd-b589-4f41b441f81fn%40googlegroups.com.


Re: Dropdown

2020-11-09 Thread Derek
Look at Django's select widgets:

https://docs.djangoproject.com/en/3.1/ref/forms/widgets/#select

If you want a dynamic search type of widget, you'll need a javascript-based 
approach; for example:

https://django-autocomplete-light.readthedocs.io/en/master/

On Thursday, 5 November 2020 at 16:06:32 UTC+2 shubham...@gmail.com wrote:

> How do you make a dropdown box in django

-- 
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/04565de5-b02a-4c85-bf93-8473ce4c2114n%40googlegroups.com.


Re: Fetching data from database

2020-10-29 Thread Derek
Have a look at:

https://www.guru99.com/python-mysql-example.html

and then:
https://www.mysqltutorial.org/python-mysql-insert/
https://www.mysqltutorial.org/python-mysql-update/

Not too hard for a beginner.

On Wednesday, 28 October 2020 at 20:43:02 UTC+2 kiran...@gmail.com wrote:

> Hi everyone,
>
> Iam stuck at a point ...I want to fetch a data from a database , where 
> data should be insert manually , plz help me how to do that how to fire a 
> queries in DB and how to use primary key and foreign key over here. 
> Please help me ,Iam new to Django . 
>
> 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/8838b1be-66dc-41e5-82c4-f2566591813cn%40googlegroups.com.


Re: Regd:- Generating PDF from HTML with image

2020-10-27 Thread Derek
You can try : https://pypi.org/project/xhtml2pdf/

On Tuesday, 27 October 2020 at 11:37:22 UTC+2 senthil...@gmail.com wrote:

> Hi Everyone,
>
> Hope you are doing well
>
> We need help to generate the PDF from the HTML tag with images. Let us 
> know if any package available to do this requirement.
>
> 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/02111ef7-0e42-40ff-930f-282599c37594n%40googlegroups.com.


Re: DJANGO forms: Improve the presentation of the elements

2020-10-26 Thread Derek
What you want to achieve (labels to the side) is the same example shown in 
the Django-crispy-forms README:

https://github.com/django-crispy-forms/django-crispy-forms



On Sunday, 25 October 2020 at 19:46:54 UTC+2 wwran...@gmail.com wrote:

> Hi guys,
>
> Is there any way to improve the distribution of the elements of the django 
> form, from this (img1) to (img2)?
>
> How so?
>
> Thanks in Advance
>
> Code:
> 
>   
> 
> {{filter.form|bootstrap}}
>   Buscar
> 
> 
>   
> %
>   
>
>id="precioinp" aria-label="Porcentaje">
>   
> .00
>   
>
>   Aplicar
> 
>   
>   
>

-- 
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/7c13edd9-4693-4441-9786-a0ded9ed9d95n%40googlegroups.com.


Re: Randomly Generate a "Certificate of Completion"

2020-10-22 Thread Derek
You'd need to have a profile for each user, so you can track if they reach 
the URL (true/false) and then use their email or internal ID or a generated 
UUID for the certificate (you could store this extra code as well if 
needed).

For generating a certificate, I'd use a PDF format; this would create a 
downloadable file they could share themselves on other platforms:
https://assist-software.net/blog/how-create-pdf-files-python-django-application-using-reportlab

Alternatively, generate a PNG image which can also be downloaded or shared 
( https://code-maven.com/create-images-with-python-pil-pillow ) - this 
could also be displayed along with their other profile info.

On Wednesday, 21 October 2020 at 17:26:16 UTC+2 Lightning Bit wrote:

> Hi All, 
>
> Where should one start to randomly generate a "Certificate of Completion" 
> with the user's name, a certificate ID, and certificate title? I want for 
> this certificate to appear upon the user making it to a specific URL and 
> for the certificate to have a special ID for each user. 
>
> Also, how would one be able to make these certificates shareable on social 
> media platforms?
>
> Thanks all, I hope that someone can help with this Django predicament.
>

-- 
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/4264068c-54b4-4b74-8c0d-f64dda24cc55n%40googlegroups.com.


Re: Periodic Execution of django functions or tasks

2020-10-20 Thread Derek
Ryan's suggestion is a very good one. 

If you don't need Django-specific commands, you can even write a 
stand-alone Python script which accesses your database to do the work. An 
alternative to cron that we use, on occasion, is 
https://pypi.org/project/APScheduler/ which runs in a container (a Python 
scheduler like this is also useful if you want to run on a non-Unix 
operating system). 

On Tuesday, 20 October 2020 at 01:53:50 UTC+2 Ryan Nowakowski wrote:

> On Mon, Oct 19, 2020 at 04:53:35PM +0300, MUGOYA DIHFAHSIH wrote:
> > Hello fellow django developers, i am working on a web app in which 
> reports
> > are archived in the database at the end of every month automatically, i
> > have searched on internet and many folks are suggesting celery which i 
> have
> > tried but not fruitful, is there any other library i use to accomplish 
> this.
> > 
>
> Yeah, celery is great! But sometimes it's too complex a beast for
> simple things. Usually I write a custom Django management command[1].
> In your case it would probably be named something like archivereports.
> Then add a cron entry to run it at the end of every month.
>
> [1] 
> https://docs.djangoproject.com/en/2.2/howto/custom-management-commands/
> [2] https://help.ubuntu.com/community/CronHowto
>

-- 
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/23e28b81-1e25-49c2-8b54-e07a8a432386n%40googlegroups.com.


Re: Template styles.

2020-10-19 Thread Derek
You can also consider using django-crispy-forms; they have a Bootstrap 
styling option:
https://django-crispy-forms.readthedocs.io/en/latest/layouts.html#bootstrap-layout-objects
and also:
https://django-crispy-forms.readthedocs.io/en/latest/install.html#template-packs
  
(for other styling options)

On Saturday, 17 October 2020 at 17:50:30 UTC+2 asm.m...@gmail.com wrote:

> Django has amazing model forms and django froms. In case if i use them, I 
> am unable to get the bootstrap and css styles. I can use raw html forms. 
> but, model forms and django forms are validated itself. in this case how 
> can I get such an amazing bootstrap styles in model forms or django forms.?

-- 
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/a8edd68c-943a-4d75-9692-6b19e4f5cfffn%40googlegroups.com.


Re: Add user to Group after purchase

2020-10-01 Thread Derek
I am not sure about your details but is my code structure.  Note that the 
signals are in the same file as the models (may be easier to start there 
first).

from django.db.models.signals import post_save


class MyModel(Model):
id = AutoField(primary_key=True)
# etc.


def MyModel_postsave_handler(sender, **kwargs):
obj = kwargs['instance']  # object that was saved!
# add logic  ...


post_save.connect(
MyModel_postsave_handler,
sender=MyModel,
dispatch_uid="mymodel.models") 


I hope this simple example can help?  Try to use pdb to see if the 
postsave_handler function is reached.

On Thursday, 1 October 2020 at 01:04:55 UTC+2 Lightning Bit wrote:

> Thanks Derek!
>
> I tried using the signals but it is not working. This is how my signals 
> and models looks:
>
> Signals.py:
> from django.contrib.auth.models import User
> from .models import *
> from django.db.models.signals import post_save
> from django.dispatch import receiver
> from django.contrib.auth.models import Group 
>
>
>
>
> @receiver(post_save, sender=User)
> def subscription_group(sender, instance, created, **kwargs):
>
> if OrderItem.product == 'Subscription_Product':
> Order.complete == True
> group = Group.objects.get(name='subscribees')
> User.groups.add(group)
> print('New Subscribee Added')
>
>
> Models.py:
> from django.db import models
> from django.contrib.auth.models import User
>
> # Create your models here.
>
> 
> class Customer(models.Model):
> user = models.OneToOneField(User, null=True, blank=True, on_delete
> =models.CASCADE )
> name = models.CharField(max_length=200, null=True)
> email = models.CharField(max_length=200, null=True)
> phone = models.CharField(max_length=200, null=True)
> profile_pic = models.ImageField(default="chicken_suit.gif" ,null=True
> , blank=True)
> data_created = models.DateTimeField(auto_now_add=True, null=True)
>
> @property
> def picURL(self):
> try:
> url = self.profile_pic.url
> except: 
> url= ''
> return url
>
> def __str__(self):
> return self.name
>
> class Product(models.Model):
> name = models.CharField(max_length=200)
> price = models.FloatField()
> digital = models.BooleanField(default=False, null=True, blank=True
> )
> image = models.ImageField(null=True, blank=True)
> view = models.URLField(default=False, null=True, blank=True)
> 
>
> def __str__(self):
> return self.name
> @property
> def imageURL(self):
> try:
> url = self.image.url
> except: 
> url= ''
> return url
>
> class Order(models.Model):
> customer = models.ForeignKey(Customer, on_delete=models.SET_NULL, null
> =True, blank=True)
> date_ordered = models.DateTimeField(auto_now_add=True)
> complete = models.BooleanField(default=False)
> transaction_id = models.CharField(max_length=100, null=True)
>
> def __str__(self):
> return str(self.id)
>
> @property 
> def get_cart_total(self):
> orderitems = self.orderitem_set.all()
> total = sum([item.get_total for item in orderitems])
> return total
> 
> @property
> def get_cart_items(self):
> orderitems = self.orderitem_set.all()
> total = sum([item.quantity for item in orderitems])
> return total
>
> @property
> def shipping(self):
> shipping= False
> orderitems = self.orderitem_set.all()
> for i in orderitems:
> if i.product.digital == False:
> shipping = True
> return shipping
>
> class OrderItem(models.Model):
> product = models.ForeignKey(Product, on_delete=models.SET_NULL, null=
> True)
> order = models.ForeignKey(Order, on_delete=models.SET_NULL, null=True)
> quantity = models.IntegerField(default=0, null=True, blank=True)
> date_added = models.DateTimeField(auto_now_add=True)
> VALUE_ADDED_TAX = 6.0
> tax= VALUE_ADDED_TAX/100
> 
>
> @property
> def get_total(self):
> total = self.product.price * self.quantity + (self.tax * self
> .product.price)
> return total
>
>
> When an individual purchases, the signal is not received and that 
> individual is not added to the "subscribees" group. 
>
> Any further suggestions?
>

-- 
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/0aa83a26-77b0-421d-93b2-d9ad5b2fcaf7n%40googlegroups.com.


Re: Add user to Group after purchase

2020-09-30 Thread Derek
You need to use a "post save" signal; see:
https://docs.djangoproject.com/en/3.1/ref/signals/#post-save

On Tuesday, 29 September 2020 at 06:23:19 UTC+2 Lightning Bit wrote:

> Hi All, 
>
> How would one add a user to a certain Backend group in the Django 
> Administration after a user purchases a particular item? I have played 
> around with tons of techniques but nothing is working. 
>
> 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/617d821c-adf7-464f-89ee-2985f089ce0fn%40googlegroups.com.


Re: Need the create statements for my Django models

2020-08-11 Thread Derek
"I was recently porting a legacy DB to Django by using the inspectdb 
command" - is there any reason why you cannot just stop here?  Why do you 
think the "inspectdb" would fail?  I would just go on creating the app and 
if any issues arise, I'd look at the specific model and see if it is 
because of a DB mismatch.  You have no control over the DB, so you'll need 
to keep adjusting your code as you go on.

On Friday, 7 August 2020 23:20:03 UTC+2, Saahitya E wrote:
>
> Hi,
>
> I was recently porting a legacy DB to Django by using the inspectdb 
> command and then manually comparing the model to the corresponding table 
> description. I want to confirm that I have not made any mistakes by getting 
> the corresponding SQL create commands that migrate would have used to 
> create the model and then comparing it to the original SQL create queries 
> in my DB. I saw that there was a python3 manage.py sql  to do 
> exactly that, but it seems to be depreciated. 
>
> Thanks and regards
> Saahitya
>
>
> PS: Using migrations is not possible as other services are using the DB.
>

-- 
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/997f639c-5298-4856-a765-026588df61aao%40googlegroups.com.


Django test runner not respecting unittest.TestCase?

2020-08-10 Thread Derek DeHart
For one of my functional tests, I decided to use unittest.TestCase instead 
of a Django test class because it was convenient when cleaning up the test 
to have direct access to my local development database in the test itself.

Running the test in isolation like so passes as I'd expect:


$ python manage.py test functional_tests.test_functionality
System check identified no issues (0 silenced).
...
--
Ran 3 tests in 0.040s

OK


When I try to run all tests at the same time, however, that test 
specifically errors out, complaining that an object DoesNotExist, as though 
it were using the Django test database:


$ python manage.py test functional_tests
Creating test database for alias 'default'...
System check identified no issues (0 silenced).
..E..
==
ERROR: some_functional_test 
(functional_tests.test_functionality.FunctionalTest)
--
Traceback (most recent call last):

... etc.

app.models.Object.DoesNotExist: Object matching query does not exist.

--
Ran 21 tests in 0.226s

FAILED (errors=1)
Destroying test database for alias 'default'...


I assume the error is with my trying use Object.objects.latest('created') 
when no Objects exist in Django's test database.

Is there some way to prevent Django from wrapping all tests in whatever it 
is about the test runner that prevents my test from accessing an Object 
directly?

I'm currently working around the issue by quarantining unittest.TestCase 
tests in their own directory so that I can run them as a suite, but it'll 
still error out if I ever want to run everything with manage.py test.

If some additional context is helpful, I'm running functional tests against 
an API endpoint running on my local server. I'm testing a create method, 
and I'm trying to avoid having to request DELETE against the endpoint (I 
haven't even implemented DELETE yet) to clean up the test record created by 
the test.

-- 
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/4afd3494-431b-4f18-b5a3-461635989e4an%40googlegroups.com.


Re: Admin list sorting problem

2020-07-31 Thread Derek
Apologies for lack of proof reading; the example code should be:


def _name(self):
return '%s' % self.name
_name.admin_order_field = 'sort_name'


On Friday, 31 July 2020 08:21:45 UTC+2, Derek wrote:
>
> I've had to do something similar to handle species.
>
> I'd suggest breaking "pure" database design and creating a new field - 
> say, "sort_name".  This is created "on save" (obviously you can run a 
> script to quickly generate this field's values for all existing records).  
> You don't show "sort_name" on the admin interface; what you then do is 
> create a new attribute on the chemical model - call it "_name"; this 
> displays the actual chemical name, but the sort is set to your new field.  
> Something like:
>
> def _name(self):
> return '%s' % self.name
> _name.admin_order_field = 'display_name'
>
> In the Admin, only show "_name" and not "sort_name" or "name".
>
> HTH
> Derek
>
> On Thursday, 30 July 2020 08:51:01 UTC+2, Mike Dewhirst wrote:
>>
>> I have looked closely at the Admin docs and the page source and I think 
>> I'm at the blank wall. 
>>
>> I have a collection of 14,000+ chemical names which just naturally sort 
>> weirdly. This is because scientists insist on incuding "locants" in 
>> chemical names. Locants indicate where sub-molecules sit in the actual 
>> whole molecule. That isn't a sufficiently scientific description but 
>> with the following example should suffice to decribe my problem. 
>>
>> 2,4-Toluene diisocyanate 
>> 2,4,6-tris(dimethylaminomethyl)phenol 
>> 2,6-Toluene diisocyanate 
>>
>> Django wants to sort this alphanumerically but scientists don't want to 
>> see it that way. 
>>
>> I wrote a chemsort algorithm and added a sort field (slug) to the model 
>> and used the model's Meta class ordering to sort the chemical according 
>> to slug. 
>>
>> 2,4,6-tris(dimethylaminomethyl)phenol->> 
>> dimethylaminomethylphenol246tris 
>> ... (many thousands more chemicals) ... 
>> 2,4-Toluene diisocyanate->> toluenediisocyanate24 
>> 2,6-Toluene diisocyanate ->> toluenediisocyanate26 
>>
>> This works fine until in the Admin, on clicking the substance name in 
>> the heading everything reverts to sorting on the name instead of the 
>> slug. 
>>
>> This is understandable because, sensibly, the Admin appears to use 
>> javascript to handle such resorting in the browser instead of making a 
>> round trip to the database via the server. Therefore, I think I need 
>> slug in the list for an in-browser solution. 
>>
>> I would like to include the slug in the Admin but severely reduce the 
>> allocated real-estate to just one or two characters. 
>>
>> How can I do that? Maybe there is another solution? 
>>
>> Thanks 
>>
>> Mike 
>>
>>
>>

-- 
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/4fc11cfc-4dec-45e7-aa19-768e7c5b2a9fo%40googlegroups.com.


Re: Admin list sorting problem

2020-07-31 Thread Derek
I've had to do something similar to handle species.

I'd suggest breaking "pure" database design and creating a new field - say, 
"sort_name".  This is created "on save" (obviously you can run a script to 
quickly generate this field's values for all existing records).  You don't 
show "sort_name" on the admin interface; what you then do is create a new 
attribute on the chemical model - call it "_name"; this displays the actual 
chemical name, but the sort is set to your new field.  Something like:

def _name(self):
return '%s' % self.name
_name.admin_order_field = 'display_name'

In the Admin, only show "_name" and not "sort_name" or "name".

HTH
Derek

On Thursday, 30 July 2020 08:51:01 UTC+2, Mike Dewhirst wrote:
>
> I have looked closely at the Admin docs and the page source and I think 
> I'm at the blank wall. 
>
> I have a collection of 14,000+ chemical names which just naturally sort 
> weirdly. This is because scientists insist on incuding "locants" in 
> chemical names. Locants indicate where sub-molecules sit in the actual 
> whole molecule. That isn't a sufficiently scientific description but 
> with the following example should suffice to decribe my problem. 
>
> 2,4-Toluene diisocyanate 
> 2,4,6-tris(dimethylaminomethyl)phenol 
> 2,6-Toluene diisocyanate 
>
> Django wants to sort this alphanumerically but scientists don't want to 
> see it that way. 
>
> I wrote a chemsort algorithm and added a sort field (slug) to the model 
> and used the model's Meta class ordering to sort the chemical according 
> to slug. 
>
> 2,4,6-tris(dimethylaminomethyl)phenol->> 
> dimethylaminomethylphenol246tris 
> ... (many thousands more chemicals) ... 
> 2,4-Toluene diisocyanate->> toluenediisocyanate24 
> 2,6-Toluene diisocyanate ->> toluenediisocyanate26 
>
> This works fine until in the Admin, on clicking the substance name in 
> the heading everything reverts to sorting on the name instead of the slug. 
>
> This is understandable because, sensibly, the Admin appears to use 
> javascript to handle such resorting in the browser instead of making a 
> round trip to the database via the server. Therefore, I think I need 
> slug in the list for an in-browser solution. 
>
> I would like to include the slug in the Admin but severely reduce the 
> allocated real-estate to just one or two characters. 
>
> How can I do that? Maybe there is another solution? 
>
> Thanks 
>
> Mike 
>
>
>

-- 
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/c3d516df-28da-4a56-adbf-0831faad9853o%40googlegroups.com.


Re: Intensive access and modification of database table

2020-07-20 Thread Derek
Its likely that Big Sites keep their detailed IP private; its unlikely that 
you are working on such a site.

Aldian is correct that there are many strategies, or combination of 
strategies you could use, and the exact one really does depend on the 
team's skills and choices of technologies.

One idea could be to use a key-value store such as Redis, which is fairly 
fast (see https://redis.io/topics/benchmarks but especially see "Pitfalls 
and misconceptions" to get some appreciation that real world problems are 
not at all trivial and most answers start with "it depends..."). You can 
use product ID as the key, linked to a pair of "current DB available; 
current total In-carts" values.  This would make lookups quick and you only 
need DB access/change when, as you say, an actual transaction is concluded.

This is just a possibility; and one of many you could employ.

Derek

On Sunday, 19 July 2020 13:18:15 UTC+2, tristant wrote:
>
> Hi,
>
> I am wondering if anyone could point me to any documents or readings on 
> how to big eCommerce sites such as Amazon or eBay implements the following 
> situation:
> - A seller posts a product with an initial quantity, 'init_qty'.
> - An unknown number of clients access the product concurrently, add it to 
> their shopping cart.
> - The site needs to manage the contemporary available quantity, 
> "avail_qty", and all times. And switch the product to "unavailable" if the 
> quantity drop to zero.
> - However, the effective "avail_qty" is only updated permanently in the 
> database if and only if the client checks out and pays.
>
> For small eCommerce sites, updating the database frequently is not a big 
> deal. But if the product count and client count is large, what is the 
> efficient way to implement this?
>
> 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/e4c7ccb3-1cfb-47ae-8b3d-3d351b1c2b25o%40googlegroups.com.


Re: My first question

2020-07-20 Thread Derek
This would make a great blog post!  And in future, we can all refer 
directly to it, when someone asks a similar question.

On Saturday, 18 July 2020 16:13:53 UTC+2, Liu Zheng wrote:
>
> Hi. Doesn't sound like a Django question, but I assume you came across 
> this question when writing Django codes:) So anyway, let me try to see 
> whether I could provide any useful information here.
>
> This question is a bit too broad, so let me try to answer it in several 
> levels.
>
> First, python doesn't care the format of any file. From python's point of 
> view, any file is just a sequence of binary data. On the lowest level, 
> python only two types of operations: read N bytes from the file starting 
> from a position; write N bytes to the file starting from a position. That's 
> it. What each byte mean is up to the programmers. So on the level of python 
> programming, there's no difference between a txt file and a csv file.
>
> Having said the first point, there are standard formats defined by 
> programmers, to make communication easier. First, among all binary files, 
> there's special type of files called "text files". It's special because 
> every byte of a text file must be a value from a certain table of symbols 
> (think of the ASCII table). Not all files are text files. But if a file is 
> a text file, then most text editors can handle that file well. (Python also 
> have native support on the language level, that is, you open a file in the 
> text mode if you use "open(, 'r')" intead of "open(, 
> 'rb')". However, this is only for sake of convenience of human readability. 
> It doesn't make a text file fundamentally different from other files. In 
> fact, you can open a text file in the binary mode using 'rb'. Python will 
> simply forget that the file is a text file.
>
> Next, text files still form a big family. By assigning meanings to 
> different symbols and creating rules of how the content should look like, 
> there are more types under text files. csv is a special type of text file. 
> (Example of othe types are .py, .html, etc). Since it's just a text file, 
> you can open a csv file using "open(, 'r')" and do 
> read/write operations like any other text file. However, since it has its 
> own rules, there are also some helper libraries to assist you handling csv 
> files, too. Examples are "csv" package, "pandas" package, etc. But again, 
> since it's a text file, you can ignore those packages and write your codes 
> using string functions directly. For example:
>
> ```
> s = open("sample.csv", 'r').read()
> lines = s.split('\n')
> first_line = lines[0]
> columns_lables = first_line.split(',')
> ..
> ```
>
> Such a piece of codes will handle a very simple and standard csv file 
> already. However, csv has more complications than this. It even has 
> different variations (called dialets). If treating a csv file as an 
> ordinary text file, you are basically re-inventing the wheel. (There's 
> nothing wrong with that. Just tedious.) Those standard packages can handle 
> those staff and let you focus on your business logic. That's all.
>
> In the end, I want to emphasize that files' extension names doesn't mean 
> anything. When I said a csv file above, I don't mean a file whose file name 
> ends with ".csv". I mean a file whose content complies the csv rules. By 
> creating a file called "something.csv", I'm merely giving a promise to 
> anyone who open it that "I promise you that the content in this file 
> satisfies the csv rules. You have my words!" Whether I keep my promise or 
> not is totally up to me (indeed, I can rename an image file "pic1.jpg" to 
> "pic1.csv".) In addition, you can save some csv data into a .txt files. For 
> example, consider the following data:
>
> Name,Job Title,Phone Number
> Alice,Manager,23121212
> Bob,Director,12345678
> Chales,Developer,41212113
>
> You can store the data into "contacts.txt". I will still call it a csv 
> file even though it has ".txt" extension. Therefore, I can handle this file 
> using any csv package. For example:
>
> ```
> import pandas as pd
> df = pd.read_csv("contacts.txt")
> ...
> ```
>
> Pandas will not complain just because its extension is not ".csv". 
> However, it will be a good practice to choose the extension which best 
> describes the nature of the file's contents. In this way, you'll bring less 
> confusion to the users of this file (including the future yourself).
>
>
>
> On Saturday, July 18, 2020 at 2:25:57 PM UTC+8, Sead Sejo Gicić wrote:
>>
>> What is the difference between ordinary txt file and csv file for using 
>> in Python programming?
>>
>

-- 
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/ac317628-2fa0-49eb-b553-9fecc74dbe99o%40googlegroups.com.


Re: Suggestions Front tool

2020-07-09 Thread Derek
You can use any of those tools to get a GUI looking exactly as you want 
(buttons, colors etc.) - a web "GUI" is not really that different from any 
others, and desktop GUIs have been around for a long time. Again, I don't 
think Django is a good fit for the use case you have described (but not 
because of the GUI aspect).

On Wednesday, 8 July 2020 13:59:46 UTC+2, kishore wrote:
>
> Hi Derek,
>
> thanks a lot for the suggestion, but i would not get good GUI in terms of 
> theme, buttons, and give the colors for specific verdicts. 
> and in future i might have to leverage the things in front GUI that i am 
> going develop for existing TCL framework. 
>
> apart from this any other suggestion would help me great, 
>
> THanks,
> Kishore. 
>  
>
> On Tue, Jul 7, 2020 at 9:00 PM Derek > 
> wrote:
>
>> You are better off using Django for what is it designed for - web-based 
>> systems - and rather use other Python alternatives for desktop-based GUIs 
>> e.g. pyQT
>> (see various resources such as 
>> https://blog.resellerclub.com/the-6-best-python-gui-frameworks-for-developers/
>>  )
>>
>> On Tuesday, 7 July 2020 14:37:24 UTC+2, kishore babu wrote:
>>>
>>> Hi, 
>>>
>>> I have TCL frame work with me, we keep on using it for our activities 
>>> currently, its CLI based and running in laptop in cmd windows
>>>  
>>> We used to open two config files and start the cli command for the 
>>> execution, but i see few mistakes and more man power is required where no 
>>> documentation needed 
>>> to give strength for my TCL frame work[in fact to my team] i thought i 
>>> can develop GUI frond end tool 
>>>
>>> *mainly 6 requirements*
>>> 1. giving few IP address, selecting the tool names, time values will be 
>>> stored in the test_configuration.cfg  
>>> 2. select the test case from search engine fetching  from TCL frame work 
>>> store it in the test_cases.cfg 
>>> 3. once the above configs done then from GUI will initiate the run 
>>> command 
>>> 4. then we shall have to monitor the execution from frame work 
>>> 5. saving the logs and opening execution report, 
>>> 6. if the test case FAIL then it should be seen on GUI RED colored if 
>>> PASSED - should be see in Green color. 
>>>
>>> here i came to ask can the Django will give me GUI front end for my TCL 
>>> frame work... rather than web based interface. 
>>>
>>> If yes where i can start, 
>>>
>>> ***i am sorry i shouldn't mentioned the frame work name or the command 
>>> to run in open forums as its proprietary tool.***
>>>
>>> Thanks,
>>> Kishore.
>>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django...@googlegroups.com .
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/a61315a8-a972-445f-8090-fb885c95be77o%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/a61315a8-a972-445f-8090-fb885c95be77o%40googlegroups.com?utm_medium=email_source=footer>
>> .
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/0d1aaa50-deb1-4d91-ad6f-156f88fc4416o%40googlegroups.com.


Re: Suggestions Front tool

2020-07-07 Thread Derek
You are better off using Django for what is it designed for - web-based 
systems - and rather use other Python alternatives for desktop-based GUIs 
e.g. pyQT
(see various resources such as 
https://blog.resellerclub.com/the-6-best-python-gui-frameworks-for-developers/
 )

On Tuesday, 7 July 2020 14:37:24 UTC+2, kishore babu wrote:
>
> Hi, 
>
> I have TCL frame work with me, we keep on using it for our activities 
> currently, its CLI based and running in laptop in cmd windows
>  
> We used to open two config files and start the cli command for the 
> execution, but i see few mistakes and more man power is required where no 
> documentation needed 
> to give strength for my TCL frame work[in fact to my team] i thought i can 
> develop GUI frond end tool 
>
> *mainly 6 requirements*
> 1. giving few IP address, selecting the tool names, time values will be 
> stored in the test_configuration.cfg  
> 2. select the test case from search engine fetching  from TCL frame work 
> store it in the test_cases.cfg 
> 3. once the above configs done then from GUI will initiate the run command 
> 4. then we shall have to monitor the execution from frame work 
> 5. saving the logs and opening execution report, 
> 6. if the test case FAIL then it should be seen on GUI RED colored if 
> PASSED - should be see in Green color. 
>
> here i came to ask can the Django will give me GUI front end for my TCL 
> frame work... rather than web based interface. 
>
> If yes where i can start, 
>
> ***i am sorry i shouldn't mentioned the frame work name or the command to 
> run in open forums as its proprietary tool.***
>
> Thanks,
> Kishore.
>

-- 
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/a61315a8-a972-445f-8090-fb885c95be77o%40googlegroups.com.


Re: Getting exception while importing data though Django Admin

2020-06-25 Thread Derek
This seems to be an error raised by a third-party library; you'd probably 
get a quicker / better response by contacting their devs.

On Thursday, 25 June 2020 00:25:18 UTC+2, Sasi Tiru wrote:
>
> Exception:
>
> \lib\site-packages\import_export\resources.py", line 581, in import_data
> raise ImproperlyConfigured
> django.core.exceptions.ImproperlyConfigured
>
>
>
>
> models.py
>
>
> class Supplier(models.Model) :
> supplier_id = models.IntegerField(primary_key=True)
> supplier_name = models.CharField(null=False, max_length=500)
>
> def __str__(self) :
> return self.supplier_name
>
>
>
> admin.py
>
> from django.contrib import admin
> from import_export.admin import ImportExportModelAdmin
>
> from .models import *
>
>
> # Register your models here.
> # @admin.register(Supplier)
> class SupplierAdmin(ImportExportModelAdmin) :
> pass
>
>
>
> resources.py
>
> from import_export import resources
>
> from .models import *
>
>
> class SupplierResource(resources.ModelResource) :
> class Meta :
> model = Supplier
> import_id_fields = ['supplier_id']
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/167ddea8-933e-4b11-a0a5-c3bcd961e4b3o%40googlegroups.com.


Re: Need Dashboard in Django Admin only

2020-05-31 Thread Derek
PS - Should be "Django REST Framework" ( 
https://github.com/encode/django-rest-framework )
 
PPS - Please don't use pie charts, especially 3D, for your visuals ( 
https://www.businessinsider.com/pie-charts-are-the-worst-2013-6?IR=T )
 
On Sunday, 31 May 2020 17:05:16 UTC+2, Derek wrote:
>
> There are numerous ways to design a front-end dashboard; this a highly 
> contested domain on the web!  
>
> Just some examples, using Django + various other tech are:
>
> * 
> https://www.highcharts.com/blog/tutorials/create-a-dashboard-using-highcharts-and-django/
> * https://dreisbach.us/articles/building-dashboards-with-django-and-d3/
> * https://morioh.com/p/88d6fc714f52
>
> I suggest you look at delivering data from the back end (your Django 
> models) with Django REST Framer (rather than hand-coded JSON); its takes a 
> bit of work to setup but its the most flexible going forward in terms of 
> future needs. e.g.
> * 
> https://medium.com/swlh/build-your-first-rest-api-with-django-rest-framework-e394e39a482c
>
> P.S. Looks like you  are trying to support work for COVID-19 - all the 
> best with that!
>
>
> On Saturday, 30 May 2020 17:08:23 UTC+2, Balaji wrote:
>>
>> Hi
>>
>>
>> If I want to generate such Dashboard in Djano Admin only
>>
>> Can anyone suggest pypi package..
>>
>> Any Sample code is available on git.
>>
>> 2 situation 
>>
>> 1. Only for 1 model
>>
>> 2 For 2 model connected by Foreign Key relationships 
>>
>>
>>
>>
>> -- 
>> Mr Shetty Balaji
>> Asst. Prof.
>> IT Department
>> SGGS I
>> Nanded. My. India
>>
>>

-- 
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/46daa73b-afa8-46d1-b6c9-7420f9edce60%40googlegroups.com.


Re: Need Dashboard in Django Admin only

2020-05-31 Thread Derek
There are numerous ways to design a front-end dashboard; this a highly 
contested domain on the web!  

Just some examples, using Django + various other tech are:

* 
https://www.highcharts.com/blog/tutorials/create-a-dashboard-using-highcharts-and-django/
* https://dreisbach.us/articles/building-dashboards-with-django-and-d3/
* https://morioh.com/p/88d6fc714f52

I suggest you look at delivering data from the back end (your Django 
models) with Django REST Framer (rather than hand-coded JSON); its takes a 
bit of work to setup but its the most flexible going forward in terms of 
future needs. e.g.
* 
https://medium.com/swlh/build-your-first-rest-api-with-django-rest-framework-e394e39a482c

P.S. Looks like you  are trying to support work for COVID-19 - all the best 
with that!


On Saturday, 30 May 2020 17:08:23 UTC+2, Balaji wrote:
>
> Hi
>
>
> If I want to generate such Dashboard in Djano Admin only
>
> Can anyone suggest pypi package..
>
> Any Sample code is available on git.
>
> 2 situation 
>
> 1. Only for 1 model
>
> 2 For 2 model connected by Foreign Key relationships 
>
>
>
>
> -- 
> Mr Shetty Balaji
> Asst. Prof.
> IT Department
> SGGS I
> Nanded. My. India
>
>

-- 
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/8415ab3f-f1da-4380-b29e-499a1fc9a803%40googlegroups.com.


Re: function model which generate a code for model field

2020-05-29 Thread Derek
I would not assume what "previous" means. Rather use post_save to get the 
actual ID of the current recording.

On Friday, 29 May 2020 12:43:19 UTC+2, Anselme SERI wrote:
>
> Hello Derek,
> Is it possible to retrieve the id of the previous recording from this 
> function? If possible I could increment it to get the id of the current 
> recording.
> Anselme S.
>
> Le ven. 29 mai 2020 à 06:08, Derek > a 
> écrit :
>
>> The suggested code will not work because, at this point, the "id" has not 
>> yet been generated by the database (unlike the other data which is 
>> typically entered by the user).
>>
>> You will need to move this code to a post_save signal function - 
>> https://docs.djangoproject.com/en/3.0/ref/signals/#post-save - where the 
>> "instance" object can be used to get the "id" value.
>>
>> On Wednesday, 27 May 2020 14:22:41 UTC+2, Kasper Laudrup wrote:
>>>
>>> Hi Anselme, 
>>>
>>>
>>> On 27/05/2020 13.33, Anselme SERI wrote: 
>>> > 
>>> > What I want to do is fill in the 'code' field of my 'Diploma' 
>>> template. 
>>> > For example, the first record of the model will have the value 
>>> > 'BAC1' in the 'code' field, the second 'BAC2', , 
>>> 'BAC01653' 
>>> > . 
>>> > The approach I have chosen to achieve this objective consists in 
>>> > defining a function in the model which will retrieve the value of the 
>>> > last id of the last record, increment it then concatenate it to the 
>>> > chain to obtain the value of the code field of the new recording. code 
>>> = 
>>> > chain + (lastid + 1) with chain = 'BAC000 ..'. I hope it's clear now? 
>>> > 
>>>
>>> There might be better ways to do this, but I would override the save() 
>>> method of your model with something like: 
>>>
>>> def save(self, *args, **kwargs): 
>>>  self.code = 'BAC{:05}'.format(self.id) 
>>>  super(MyModel, self).save(*args, **kwargs) 
>>>
>>> Untested, but hopefully you get the idea. 
>>>
>>> Kind regards, 
>>>
>>> Kasper Laudrup 
>>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django...@googlegroups.com .
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/bad64876-a692-463a-99af-5d491841d5a1%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/bad64876-a692-463a-99af-5d491841d5a1%40googlegroups.com?utm_medium=email_source=footer>
>> .
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/1d759e75-e933-4fcf-9d82-8c52c9e080fc%40googlegroups.com.


Re: function model which generate a code for model field

2020-05-29 Thread Derek
The suggested code will not work because, at this point, the "id" has not 
yet been generated by the database (unlike the other data which is 
typically entered by the user).

You will need to move this code to a post_save signal function - 
https://docs.djangoproject.com/en/3.0/ref/signals/#post-save - where the 
"instance" object can be used to get the "id" value.

On Wednesday, 27 May 2020 14:22:41 UTC+2, Kasper Laudrup wrote:
>
> Hi Anselme, 
>
>
> On 27/05/2020 13.33, Anselme SERI wrote: 
> > 
> > What I want to do is fill in the 'code' field of my 'Diploma' template. 
> > For example, the first record of the model will have the value 
> > 'BAC1' in the 'code' field, the second 'BAC2', , 'BAC01653' 
> > . 
> > The approach I have chosen to achieve this objective consists in 
> > defining a function in the model which will retrieve the value of the 
> > last id of the last record, increment it then concatenate it to the 
> > chain to obtain the value of the code field of the new recording. code = 
> > chain + (lastid + 1) with chain = 'BAC000 ..'. I hope it's clear now? 
> > 
>
> There might be better ways to do this, but I would override the save() 
> method of your model with something like: 
>
> def save(self, *args, **kwargs): 
>  self.code = 'BAC{:05}'.format(self.id) 
>  super(MyModel, self).save(*args, **kwargs) 
>
> Untested, but hopefully you get the idea. 
>
> Kind regards, 
>
> Kasper Laudrup 
>

-- 
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/bad64876-a692-463a-99af-5d491841d5a1%40googlegroups.com.


Re: Can we use python related api's on the Django templates ?

2020-05-28 Thread Derek
While you cannot use Python operators and functions directly in the 
templates, you can write your own "wrappers" around those you need:

https://docs.djangoproject.com/en/3.0/howto/custom-template-tags/


On Wednesday, 27 May 2020 15:57:34 UTC+2, Daniel Roseman wrote:
>
> On Wednesday, 27 May 2020 13:21:24 UTC+1, ratnadeep ray wrote:
>>
>> Hi all, 
>>
>> Currently I am trying to print the type of a variable from the Django 
>> template html file as follows: 
>>
>> The type of feature list report for version 
>>> {%type(version)%} is
>>
>>
>> For the above, I am getting the following error: 
>>
>> Invalid block tag on line 9: 'type(version)'. Did you forget to register or 
>> load this tag?
>>
>>
>> So what's going wrong here? How can we use the python related api's (like 
>> type) from the html template files? I think inside the {%  %} we can 
>> use python related evaluations. Am I right? 
>>
>> Please throw some lights on this .
>>
>> Thanks. 
>>
>>
> No, you are wrong, and this is explicitly pointed out in the docs (
> https://docs.djangoproject.com/en/3.0/ref/templates/language/):
>
> > bear in mind that the Django template system is not simply Python 
> embedded into HTML. This is by design: the template system is meant to 
> express presentation, not program logic.
>
> --
> DR. 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/09e739dd-60c8-4360-9f9f-d3270c7901ca%40googlegroups.com.


Re: Regarding redering data in html templates

2020-05-27 Thread Derek
Lots of examples out there, but here is one:

https://www.gun.io/blog/how-to-list-items-in-a-dictionary-in-a-django-template

For working with static files (such as CSS or images), have a look at:

https://scotch.io/tutorials/working-with-django-templates-static-files

On Monday, 25 May 2020 17:06:25 UTC+2, Karthiki Chowdary wrote:
>
> Hi i was beginner in django and i have a small query in templates. 
> For suppose in the home page of any client browser if we have a button 
> like SKINCARE or HEALTH CARE and if we click on that buttons we need to get 
> the data of all skin care products companies logos/ health care companies 
> logos. For that how i can render data in dictionaries suppose i want to 
> render a static data how can i or i want or render a dynamic data how can i 
> do that with dictionaries so other better option. Please help me out in this
>

-- 
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/8a4f13dc-c4fe-40aa-a892-0afc6981847c%40googlegroups.com.


Re: function model which generate a code for model field

2020-05-27 Thread Derek
Its not clear what you mean by "last"; do you mean a record that already 
exists in the database and has a ID value - or do you want the ID of the 
current record?  Either way, the code field should not be resetting the '0' 
to a '1' as this is then misrepresenting the actual data.

PS The logic to create the string looks a bit clunky; why not use rjust to 
get the correct number of prefix zeros?

On Monday, 25 May 2020 22:33:30 UTC+2, Anselme SERI wrote:
>
> hello,
> I am trying to create a function which will recover the last id of my 
> model which I will increment and add to a character string, and I would 
> like to add this new value (x = last id incremented + string) be added to 
> the "code" field "of my model when I make a new recording.
> How else could we use the id field which automatically increments to 
> perform such an action?
>
> Anselme S.
>
> Le dim. 24 mai 2020 à 20:12, Kasper Laudrup  > a écrit :
>
>> Hi Anselme,
>>
>> On 24/05/2020 17.48, Anselme SERI wrote:
>> > 
>> > I try  to to write a correct function for my model which  generate a 
>> str 
>> > + incremental number according last id model.
>> > 
>>
>> Your code is obviously wrong for quite a few reasons, but I at least 
>> simply cannot understand what you are trying to achieve.
>>
>> What should the "correct function" do?
>>
>> The id field of a model is already incremental. Do you simply want to 
>> append that to a string and what do you want to do with that string?
>>
>> Kind regards,
>>
>> Kasper Laudrup
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django...@googlegroups.com .
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/65ffe493-1190-619a-f904-fbe35b60e3e3%40stacktrace.dk
>> .
>>
>

-- 
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/f8725fd3-bf12-4b82-b1d6-e8569d7220ff%40googlegroups.com.


Re: JSON file

2020-05-25 Thread Derek
I am not sure about the field names part, but you could probably create 
that manually very easily.

For the data section, you need a list of lists, which you can get from code 
like:

import json
data_ready_for_json = 
list(mail_item_count_deliveries_perDate.objects.values_list('countDeliveries','Dates'))
json_string = json.dumps(data_ready_for_json)

(P.S. you may want to consider giving your classes more Python-like names 
e.g. class MailDelivery )


On Friday, 22 May 2020 19:48:36 UTC+2, HJ wrote:
>
> hello django users hope you are doing well 
>
> I want to do a highchart using a json file , and that's the problem I am 
> facing , I want to create a json file in my views.py based on my columns 
> below "countDeliveries"and "Dates"
>
> class mail_item_count_deliveries_perDate(models.Model):
>countDeliveries = models.IntegerField(default=0)
>Dates = models.DateTimeField()
>
>
> myJSON file should be something like that:
>  
>
> [
> [
> Dates,
> countDeliveries
> ],
> [
> 116769600,
> 5
> ],
>
>
>  
> - can you guys help me out 
>

-- 
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/19830969-d813-4e51-9016-b9b820945b92%40googlegroups.com.


Re: Database audit fields in Django

2020-05-25 Thread Derek
There are many things available "by default" in other frameworks; but 
Django has chose to keep the core focused on doing key things well (I won't 
say "simple").  For everything else, the plugin/app approach can be used to 
support your project's specific needs.

So "auditing" is actually a complex issue and no one person or organisation 
will define this the same way.  However, there are some good apps out there 
that might support at least some of what you need; for example:

https://github.com/treyhunner/django-simple-history

https://github.com/jjkester/django-auditlog

I'd look at those before considering writing any code yourself.
 

On Friday, 22 May 2020 23:40:02 UTC+2, Sujata Aghor wrote:
>
> I am looking to create a database audit fields such as 'created by' , ' 
> modified by', 'created on time', ' modified on time' and Archive table 
> where i can see the changes over the time about perticular row.
>
> this was possible in web2py automatically. Does anyone knows any such 
> thing exist in Django?
> Any idea will be a gr8 help.
> 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/54620e24-43d5-4609-9198-92db29ee53a4%40googlegroups.com.


Re: HOW TO PROTECT SOURCE CODE DEPLOYED TO A REMOTE SERVER

2020-05-21 Thread Derek
No; a container is not going to hep with this - see:
https://stackoverflow.com/questions/51574618/preventing-access-to-code-inside-of-a-docker-container
(they specifically mention Python in the answer).

On Wednesday, 20 May 2020 17:20:24 UTC+2, James Shen wrote:
>
> try to deploy using a container technology like a docker , only expose 
> port 80, and keep the login to SSH to yourself.
>
> On Wed, May 20, 2020 at 4:54 PM John McClain  > wrote:
>
>> Hello Sunday,
>>
>> I wonder if you could deploy to git and use one of the licenses there to 
>> protect the code. I think they would be bound by the use the license 
>> permits. Have you looked at this as a possibility?
>>
>> John
>>
>> On Tue, 19 May 2020 at 02:35, Sunday Iyanu Ajayi > > wrote:
>>
>>> I get your point but my solution is kind of a  SaaS Application. the 
>>> client wants to host it on his controlled server  and if they get the 
>>> source code, they can replicate, modify and maybe sell it.  Is there a way 
>>> to host the compiled file or lock the directory to the project.
>>> *AJAYI Sunday *
>>> (+234) 806 771 5394
>>> *sunne...@gmail.com *
>>>
>>>
>>>
>>> On Mon, May 18, 2020 at 9:28 PM Jim Armstrong >> > wrote:
>>>
 When I work on client projects, I deploy to a test server that is under 
 my control. Once the project is complete and they have paid the invoice, I 
 deploy to the production server under their control. At that point, I 
 don't 
 care if they have access to the code - my contracts give the clients all 
 rights to the project code upon completion of the project.


 On Friday, May 15, 2020 at 9:22:33 AM UTC-4, Sunday Iyanu Ajayi wrote:
>
> I am working for a client that wants to deploy a project I am working 
> on in a remote server and I will like to project my source code when 
> deployed so that they will not be able to mess with it. 
>
> How can  I  go about it please? 
>
> *AJAYI Sunday *
> (+234) 806 771 5394
> *sunne...@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...@googlegroups.com .
 To view this discussion on the web visit 
 https://groups.google.com/d/msgid/django-users/636f0636-30df-4ce2-8629-2be8b208ec37%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...@googlegroups.com .
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/django-users/CAKYSAw3Hqjuz5rD_AsZ5Wa%2B3WBzQ9LN0GzZKHx3D-irztJ1G0A%40mail.gmail.com
>>>  
>>> 
>>> .
>>>
>>
>>
>> -- 
>> John McClain
>>
>> Cell: 085-1977-823
>> Skype: jmcclain0129
>> Email: jmccla...@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...@googlegroups.com .
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/CAN-hv_pbGUu7Qjm%2BZO7fOmT2H1W2C8Xy%2BhTk_6_BQcUcwc-XbA%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/9481e5de-a399-41c9-94e0-a3f1daecf25b%40googlegroups.com.


Re: HOW TO PROTECT SOURCE CODE DEPLOYED TO A REMOTE SERVER

2020-05-20 Thread Derek
Yes - short answer is you cannot really "protect" Python code directly 
(see: https://python-compiler.com/post/how-to-distribute-python-program ) 

Long answer - don't sell your code to anyone that you do not trust with 
it.  Obviously, there is a legal route, but there is also the "name and 
shame" option.  Sometimes open source is better; you get paid for your time 
to work on the code rather than trying to sell it as a product - which then 
you have to try and protect.  The open source option prevents the company 
from "selling" the code (well, they would look very silly if they tried to 
do that) and establishes you as the "go to" person for creating and 
maintaining that type of system. If they do make changes to the open source 
code, you'd get the benefit as well.  

In general, try and create partnerships with your clients so they want to 
include you in the development process, rather than treating each as other 
as competitors.


On Tuesday, 19 May 2020 15:22:13 UTC+2, Andréas Kühne wrote:
>
> You can't really do that with Python - however - IF you want to go down 
> that route, you can just use the pyc files - you can theoretically 
> backwards compile them, but I think this is the most you can do 
>
> Regards,
>
> Andréas
>
>
> Den tis 19 maj 2020 kl 03:36 skrev Sunday Iyanu Ajayi  >:
>
>> I get your point but my solution is kind of a  SaaS Application. the 
>> client wants to host it on his controlled server  and if they get the 
>> source code, they can replicate, modify and maybe sell it.  Is there a way 
>> to host the compiled file or lock the directory to the project.
>> *AJAYI Sunday *
>> (+234) 806 771 5394
>> *sunne...@gmail.com *
>>
>>
>>
>> On Mon, May 18, 2020 at 9:28 PM Jim Armstrong > > wrote:
>>
>>> When I work on client projects, I deploy to a test server that is under 
>>> my control. Once the project is complete and they have paid the invoice, I 
>>> deploy to the production server under their control. At that point, I don't 
>>> care if they have access to the code - my contracts give the clients all 
>>> rights to the project code upon completion of the project.
>>>
>>>
>>> On Friday, May 15, 2020 at 9:22:33 AM UTC-4, Sunday Iyanu Ajayi wrote:

 I am working for a client that wants to deploy a project I am working 
 on in a remote server and I will like to project my source code when 
 deployed so that they will not be able to mess with it. 

 How can  I  go about it please? 

 *AJAYI Sunday *
 (+234) 806 771 5394
 *sunne...@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...@googlegroups.com .
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/django-users/636f0636-30df-4ce2-8629-2be8b208ec37%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...@googlegroups.com .
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/CAKYSAw3Hqjuz5rD_AsZ5Wa%2B3WBzQ9LN0GzZKHx3D-irztJ1G0A%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/021a40fa-a755-4d77-addf-dfd112597dbc%40googlegroups.com.


Re: Django Model

2020-05-14 Thread Derek
>>> from django.apps import apps
>>> apps.all_models['app_name']

So if your app is called, for example, products, then:

>>> apps.all_models['products']

Will create a dictionary with all the model classes from that app.

On Thursday, 14 May 2020 14:03:40 UTC+2, muazzem_ hossain wrote:
>
> how to get django all app model.
>

-- 
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/2406a55d-8d5a-406d-ba61-aee086a11352%40googlegroups.com.


Re: Can I use a JS Framework to display small JS tasks in a Django project?

2020-05-13 Thread Derek
Its not clear why you need JS at all. The app can load content from 
directories on the server side (back-end) and write these to a DB.  Django 
could then load these from the DB and show in the normal way.  Page 
generation can be done via normal views (Django/Python code).

(PS Both react and angular are not "new" - each are over 6 years old; more 
than 2 generations of computer science students...)


On Tuesday, 12 May 2020 16:04:55 UTC+2, Alexander Rogowski wrote:
>
> I have an idea to simplify the online experiments from our university. But 
> I'm not so familiar with the newest FE frameworks eg. react, angular, vue. 
> Any answer on this post is appreciated :)
>
> The idea is, to put our experiments in two folders, "tasks" and 
> "treatments". A task could be something trivial like put some sliders on 
> the right position or write with a chatbot (this should be coded in js, I 
> guess?) and in treatments could be something like collecting badges or the 
> setting for the chatbot (e.g. human-like/machine-like).
>
> My question is: Can I use a JS Framework to load the content from the two 
> directories and show them as options on a main page? After selecting the 
> task and the treatments, it would generate a page with the selected items, 
> e.g. the chatbot with the human-like setting.
>
> I Would like to do this with Django (because I already worked with it) so 
> we can create unique links to send them to the probands. Is Django with a 
> JS Framework the right decision? How would you approach the problem?
>

-- 
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/d673c088-20f0-40a7-916e-346979e55a71%40googlegroups.com.


  1   2   3   4   5   6   7   8   9   10   >