Wednesday, May 31, 2017

Re: duplicate key value violates unique constraint "django_admin_log_pkey"

Helped me too. Thanks.

On Thursday, October 14, 2010 at 8:54:30 PM UTC+5:30, glob...@iamsandiego.com wrote:
Hi Folks,

After updating a postgres db for my django app Iam getting this error
when I try and save new data to the db:

Request Method:          POST
Request URL:         http://10.50.253.200/admin/survey/gps/add/
Django Version:         1.2 beta 1
Exception Type:         IntegrityError
Exception Value:

duplicate key value violates unique constraint "django_admin_log_pkey"

Is there any way to correct 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+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/1245de5c-d8fb-4930-a6f2-a273b2d38739%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Re: Restricting the user from closing the browser tab so that the server side APIs are called.

Rahul,

I don't think you're going to find a reliable way to ensure that the
APIs are called from the browser.  There are too many ways for
the user to close the browser, or for the browser to crash, or for
the browser to lose connectivity to the server unexpectedly
(ISP has a glitch, local wireless router has a glitch, laptop carried
too far from the WiFi router, cell phone enters a tunnel or drives
into some other dead zone), etc.

Instead, you may want to do something like this to handle the
cases where the user never clicks your end-call button:
- Have a frequent timer in the browser make an Ajax call to the
   server saying that it is still active -- a "keep-alive" or "heartbeat"
   call, as it is sometimes known.
- Have a server-side process do the necessary cleanup that the API
   call would have done, but only if the keep-alive calls stop coming
   in.

--Fred

Fred Stluka -- mailto:fred@bristle.com -- http://bristle.com/~fred/
Bristle Software, Inc -- http://bristle.com -- Glad to be of service!
Open Source: Without walls and fences, we need no Windows or Gates.

On 5/31/17 5:05 PM, Rahul Paul wrote:
Hi,

We are working on a django project in which we are developing a two way audio visual solution for the users. Now we have certain set of APIs that need to be called from JavaScript through ajax request when user ends the call through our end-call button. Some of these ajax calls are sequential i.e. based on result of one ajax call another ajax call is made.

Now our problem is if the user close the tab or browser using the cross button of tab or browser, then these APIs are not called and many of our functionalities does not work. Hence to solve this we were looking into the following options : 

1. Restricting the user from closing the tab or browser until the user clicks on end-call button and all functionalities related to ending the call is done.
2. Calling the APIs before the browser or tab close when user tries to close the browser or tab.
3. Opening our template as a modal so that we can modify the closing of modal to satisfy our use case.

First option is not possible since it poses security risks w.r.t. browser. Currently our web page is opening as new tab. We have tried opening the page as new window and hiding the menu bar, minimize/maximize and cross button, but we could not hide the cross button. 

We tried the second option using window.onbeforeunload and window.onunload feature of JavaScript window object, but we could not call the APIs.

We are now thinking of the third option, but here we are stuck as we are not sure if the template can be directly rendered as a modal from django views. 

Also our web page will have the following major components : 

* video tag, where 2-way A/V will play.
* iframe where we have another feature.
* chat section where communication happens through django channels.
* File upload and download feature.
* Many functionalities are based on API call hence many ajax request.

In short our web page will be heavy and will have a lot of javascript files to be loaded. So will we get the same efficiency with modal as we get with proper web page? What will be the limitation and if possible how we can render our template as modal?

Our main intention have the same flow when the user clicks the end-call button or close the tab or browser i.e. all the functionalities that are happening when end-call button is clicked, must also happen when the user close the tab or browser.

Please help me with resolving this issue. You can also provide options other then what we have considered. All suggestions are 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+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/c0aff7ca-137a-4b28-80ab-a246f35dd4df%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Re: Restricting the user from closing the browser tab so that the server side APIs are called.

On Wednesday 31 May 2017 14:05:14 Rahul Paul wrote:

 

> We are working on a django project in which we are developing a two

> way audio visual solution for the users. Now we have certain set of

> APIs that need to be called from JavaScript through ajax request when

> user ends the call through our end-call button.

 

So fix that design flaw. If the user experiences a power outage or loss of internet connectivity, no JS / browser hacking will save you.

 

As with any 2-way connection, code for disconnects through timeouts, then do your cleanups.

 

--

Melvyn Sopacua

Re: ModelFormset Into InlineFormset



On Wed, May 31, 2017 at 3:13 PM, Matthew Pava <Matthew.Pava@iss.com> wrote:

I have a class CustomFormSet that inherits from BaseModelFormSet.  I would like to have another formset class that does everything CustomFormSet does but instead inherits from BaseInlineFormSet.  What is the best pythonic/Django way of doing that?

 


I would take the same approach that abstract model classes use. Collect the common functionality into a separate class, and mix the forms together with the desired inheritance hierarchy.

Since your inheritance hierarchy includes the Base*FormSet classes, your abstract form mixin can simply inherit from object to keep from adding unintended behavior. 

-James  

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CA%2Be%2BciX9xDt3moEQPGdgy3SBt3xvPV3z3eUGun6eq%3DMSPKh_hQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Re: count from multiple tables in a single query?



On Wed, May 31, 2017 at 3:01 PM, Alceu Rodrigues de Freitas Junior <alceu.freitas.jr@gmail.com> wrote:

Hi James,

I'm curious... why dropping down from the ORM and doing a single query wouldn't be portable?

I understand that it would happen if you use some kind of stored procedure in the DB, but I guess a single ANSI SQL would do it.

Thanks!

- Alceu


I might have painted that statement with too broad of a brush, but the underlying intention is correct. Sticking with the ORM ensures consistent behavior across all supported database backends. In the case of a simple COUNT(*) query, even with multiple tables involved, the SQL statement is likely portable across any of the included backends. 

My intention was to say that using the ORM will better guarantee that the call is portable, not necessarily saying that raw SQL cannot or would not be. Of course, many queries can be made that would work in any SQL-compliant RDBMS. 

At any rate, a quick Google showed that the OP is likely stuck with two queries anyway. The SO posts, etc. show sub-SELECT statements in use in order to get the result returned as a single data set. 

-James

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CA%2Be%2BciVGXcWG65%2BGz3%3DoVP4c6YeZM8rPcorFjhe-S_xOGMytZA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

ModelFormset Into InlineFormset

I have a class CustomFormSet that inherits from BaseModelFormSet.  I would like to have another formset class that does everything CustomFormSet does but instead inherits from BaseInlineFormSet.  What is the best pythonic/Django way of doing that?

 

Re: count from multiple tables in a single query?

Hi James,

I'm curious... why dropping down from the ORM and doing a single query wouldn't be portable?

I understand that it would happen if you use some kind of stored procedure in the DB, but I guess a single ANSI SQL would do it.

Thanks!

- Alceu


Em 31/05/2017 17:29, James Schneider escreveu:

If I want to get the total count from both tables it can be done like this,

author_count = Author.objects.count()
publisher_count
= Publisher.objects.count()

My concern is that this results in two different queries to the database. Can it be done with a single query call?



Probably not with the standard ORM and the model setup you provided with no relation between the tables. You'll likely have to drop down to raw SQL. I'd do testing. I doubt you'll have much of a performance gain by combining the two queries in to one since you are just doing a count and both tables have unique indexes, aside from saving the overhead of one SQL call (not the actual query itself). Two calls would keep the code simple and portable, which to me is more important than a marginal gain in performance.

-James
--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CA%2Be%2BciVxVrzLuF7ASWiC34A2MenWvJd3P1GXsP%2Bi-mYQ9FuVvg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Re: count from multiple tables in a single query?

Hello James/Matthew,

I was afraid to hear that. The models are unrelated and I do not want to take the trouble of dropping out of the ORM. Since it's a web-service I'm building, a work-around is to cache results, but I was challenged to find a single DB call solution and wanted to be sure that it wouldn't be possible with the ORM.

Thanks for replying!

Looking into caches,
Abraham V.


On Wednesday, 31 May 2017 16:31:04 UTC-4, Matthew Pava wrote:

Hi Abraham,

If the models are related, you can use double underscore notation with the Count aggregate function.

If the models are unrelated, then I'm fairly certain that you can only use separate queries to get your results.

 

 

From: 'Abraham Varricatt' via Django users [mailto:django...@googlegroups.com]
Sent: Wednesday, May 31, 2017 2:14 PM
To: Django users
Subject: count from multiple tables in a single query?

 

Hello,

Is it possible to get the count of entries from multiple tables in a single query call? I'm looking at the official docs on aggregation and I can't find anything. For example assume I have the following 2 tables,

class Author(models.Model):
    name
= models.CharField(max_length=100)
    age
= models.IntegerField()

class Publisher(models.Model):
    name
= models.CharField(max_length=300)
    num_awards
= models.IntegerField()


If I want to get the total count from both tables it can be done like this,

author_count = Author.objects.count()
publisher_count
= Publisher.objects.count()


My concern is that this results in two different queries to the database. Can it be done with a single query call?


Yours,
Abraham V.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to djang...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/5ffdbc1a-fb84-4bff-a711-eaad77c3ae15%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/7b99f473-0ea3-4d0a-acd2-08b05c96d687%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Restricting the user from closing the browser tab so that the server side APIs are called.

Hi,

We are working on a django project in which we are developing a two way audio visual solution for the users. Now we have certain set of APIs that need to be called from JavaScript through ajax request when user ends the call through our end-call button. Some of these ajax calls are sequential i.e. based on result of one ajax call another ajax call is made.

Now our problem is if the user close the tab or browser using the cross button of tab or browser, then these APIs are not called and many of our functionalities does not work. Hence to solve this we were looking into the following options : 

1. Restricting the user from closing the tab or browser until the user clicks on end-call button and all functionalities related to ending the call is done.
2. Calling the APIs before the browser or tab close when user tries to close the browser or tab.
3. Opening our template as a modal so that we can modify the closing of modal to satisfy our use case.

First option is not possible since it poses security risks w.r.t. browser. Currently our web page is opening as new tab. We have tried opening the page as new window and hiding the menu bar, minimize/maximize and cross button, but we could not hide the cross button. 

We tried the second option using window.onbeforeunload and window.onunload feature of JavaScript window object, but we could not call the APIs.

We are now thinking of the third option, but here we are stuck as we are not sure if the template can be directly rendered as a modal from django views. 

Also our web page will have the following major components : 

* video tag, where 2-way A/V will play.
* iframe where we have another feature.
* chat section where communication happens through django channels.
* File upload and download feature.
* Many functionalities are based on API call hence many ajax request.

In short our web page will be heavy and will have a lot of javascript files to be loaded. So will we get the same efficiency with modal as we get with proper web page? What will be the limitation and if possible how we can render our template as modal?

Our main intention have the same flow when the user clicks the end-call button or close the tab or browser i.e. all the functionalities that are happening when end-call button is clicked, must also happen when the user close the tab or browser.

Please help me with resolving this issue. You can also provide options other then what we have considered. All suggestions are 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+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/c0aff7ca-137a-4b28-80ab-a246f35dd4df%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

RE: count from multiple tables in a single query?

Hi Abraham,

If the models are related, you can use double underscore notation with the Count aggregate function.

If the models are unrelated, then I'm fairly certain that you can only use separate queries to get your results.

 

 

From: 'Abraham Varricatt' via Django users [mailto:django-users@googlegroups.com]
Sent: Wednesday, May 31, 2017 2:14 PM
To: Django users
Subject: count from multiple tables in a single query?

 

Hello,

Is it possible to get the count of entries from multiple tables in a single query call? I'm looking at the official docs on aggregation and I can't find anything. For example assume I have the following 2 tables,

class Author(models.Model):
    name
= models.CharField(max_length=100)
    age
= models.IntegerField()

class Publisher(models.Model):
    name
= models.CharField(max_length=300)
    num_awards
= models.IntegerField()


If I want to get the total count from both tables it can be done like this,

author_count = Author.objects.count()
publisher_count
= Publisher.objects.count()


My concern is that this results in two different queries to the database. Can it be done with a single query call?


Yours,
Abraham V.

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/5ffdbc1a-fb84-4bff-a711-eaad77c3ae15%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Re: count from multiple tables in a single query?


If I want to get the total count from both tables it can be done like this,

author_count = Author.objects.count()
publisher_count
= Publisher.objects.count()

My concern is that this results in two different queries to the database. Can it be done with a single query call?



Probably not with the standard ORM and the model setup you provided with no relation between the tables. You'll likely have to drop down to raw SQL. I'd do testing. I doubt you'll have much of a performance gain by combining the two queries in to one since you are just doing a count and both tables have unique indexes, aside from saving the overhead of one SQL call (not the actual query itself). Two calls would keep the code simple and portable, which to me is more important than a marginal gain in performance.

-James

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CA%2Be%2BciVxVrzLuF7ASWiC34A2MenWvJd3P1GXsP%2Bi-mYQ9FuVvg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

count from multiple tables in a single query?

Hello,

Is it possible to get the count of entries from multiple tables in a single query call? I'm looking at the official docs on aggregation and I can't find anything. For example assume I have the following 2 tables,

class Author(models.Model):
   
name = models.CharField(max_length=100)
   
age = models.IntegerField()

class Publisher(models.Model):
   
name = models.CharField(max_length=300)
   
num_awards = models.IntegerField()

If I want to get the total count from both tables it can be done like this,

author_count = Author.objects.count()
publisher_count
= Publisher.objects.count()

My concern is that this results in two different queries to the database. Can it be done with a single query call?


Yours,
Abraham V.

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/5ffdbc1a-fb84-4bff-a711-eaad77c3ae15%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Re: value of checkbox aren't saved in the form

Your checkbox fields on the form are "market" and "sector", but your
"Parameters" model doesn't have fields with those names, and you
aren't doing anything with the values from the form in your save()
method.

Where were you expecting those checkboxes to be saved?

Cheers

Tom

On Wed, May 31, 2017 at 1:15 PM, <farah_chaaban@hotmail.com> wrote:
> i am a beginner with Django. I don''t know what the problem with the value
> of checkbox. When i enter to the saved form the value of checkbox aren't
> save.The image is here . Please I need your help, I loose too much time on
> this.
>
> This is my forms.py:
>
> class BacktestForm(forms.ModelForm):
>
> period_start = forms.DateField(initial=datetime.datetime.today().date() -
> datetime.timedelta(days=365+16),
> widget=forms.widgets.DateInput(format="%Y/%m/%d"),
> input_formats=["%Y/%m/%d"])
> period_end = forms.DateField(initial=datetime.datetime.today().date() -
> datetime.timedelta(days=16),
> widget=forms.widgets.DateInput(format="%Y/%m/%d"),
> input_formats=["%Y/%m/%d"])
>
> market =
> forms.MultipleChoiceField(required=False,widget=CheckboxSelectMultiple,
> choices=MARKET_CHOICES)
> sector =
> forms.MultipleChoiceField(required=False,widget=CheckboxSelectMultiple,
> choices= MEDIA_CHOICES)
> class Meta:
> model = Parameters
>
> This is my models.py:
>
> class Parameters(models.Model):
>
> user = models.ForeignKey(User)
> title = models.CharField('title', max_length=100, default='', blank=True,
> help_text='Use an indicative name, related to the chosen parameters')
> type = models.CharField('forecast type', choices=FORECAST_TYPES,
> max_length=20, default="backtest")
>
> #input characteristics
> price_1_min = models.FloatField('1. Price, min', default=0.1,
> validators=[MinValueValidator(0.1), MaxValueValidator(20000)])
>
> def get_backtest_url(self):
> return reverse('saved_backtest', kwargs={'pk': self.pk})
>
>
> The save function in views.py:
>
>
> if request.method == 'POST':
> if form.is_valid():
> if 'save' in request.POST:
> obj = form.save(commit= False)
> obj.user = request.user
> obj.type = "backtest"
> obj.save()
> messages.info(request, 'Saved!')
> return redirect(obj.get_backtest_url())
>
>
> The template for the saved form is :
>
> <div> {% if user.is_authenticated %}
> {% if user.profile.is_active %}
> &nbsp; Saved from "Backtesting"
> <ul>
> {% for param in user.parameters_set.all %}
> {% if param.type == "backtest" %}
> <table
> style="width:100%">
> <tr>
> <th> Saved File
> </th>
> <th> Created at
> </th>
>
> <tr>
>
> <td> <a
> href='{{param.get_backtest_url}}'>{{param.title}} </a> </td>
> <td> {{param.created_at}} </td>
>
> </tr>
> </table>
> {% endif %}
> {% endfor %}
> </ul>
>
> --
> 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+unsubscribe@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/55e259b4-8986-41d0-849e-4fe809001ff0%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAFHbX1KXUD5%3DZRT%2Bu4k3EBLnzC%3D5MLt6LCPO-UX%2BWJrLrAT5wQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Re: Django db backend not FIPS compliant

django-developers discussion: https://groups.google.com/d/msg/django-developers/dlUIPzQgnpM/Mtl7CQbPAQAJ

On Tuesday, May 30, 2017 at 5:06:23 PM UTC-4, Tim Graham wrote:
This usage generates a short, unique identifier for a database index name. The usage of md5 here isn't security sensitive. Changing it to some other hash could be backwards incompatible because Django would no longer know the names of indexes in existing projects. There are other usages of md5 in Django where a short, fast hash is needed. I'm not sure if prohibiting the usage of md5 in Django or adding a setting to allow selecting some other hash in all those places is worth the additional complexity but you could write to django-developers to get other opinions.

On Tuesday, May 30, 2017 at 4:21:24 PM UTC-4, Brandon Williams wrote:
I'm running into issues when trying to migrate my models in an environment that is running FIPS restrictions regarding MD5.  Here is the stack trace:

Operations to perform:
  Apply all migrations: admin, auth, contenttypes, dashboard, kombu_transport_django, sessions
Running migrations:
  Applying contenttypes.0001_initial...Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/lib64/python2.7/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
    utility.execute()
  File "/usr/lib64/python2.7/site-packages/django/core/management/__init__.py", line 359, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/lib64/python2.7/site-packages/django/core/management/base.py", line 294, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/usr/lib64/python2.7/site-packages/django/core/management/base.py", line 345, in execute
    output = self.handle(*args, **options)
  File "/usr/lib64/python2.7/site-packages/django/core/management/commands/migrate.py", line 204, in handle
    fake_initial=fake_initial,
  File "/usr/lib64/python2.7/site-packages/django/db/migrations/executor.py", line 115, in migrate
    state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
  File "/usr/lib64/python2.7/site-packages/django/db/migrations/executor.py", line 145, in _migrate_all_forwards
    state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
  File "/usr/lib64/python2.7/site-packages/django/db/migrations/executor.py", line 244, in apply_migration
    state = migration.apply(state, schema_editor)
  File "/usr/lib64/python2.7/site-packages/django/db/migrations/migration.py", line 129, in apply
    operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
  File "/usr/lib64/python2.7/site-packages/django/db/migrations/operations/models.py", line 532, in database_forwards
    getattr(new_model._meta, self.option_name, set()),
  File "/usr/lib64/python2.7/site-packages/django/db/backends/base/schema.py", line 333, in alter_unique_together
    self.execute(self._create_unique_sql(model, columns))
  File "/usr/lib64/python2.7/site-packages/django/db/backends/base/schema.py", line 913, in _create_unique_sql
    "name": self.quote_name(self._create_index_name(model, columns, suffix="_uniq")),
  File "/usr/lib64/python2.7/site-packages/django/db/backends/base/schema.py", line 819, in _create_index_name
    index_unique_name = '_%s' % self._digest(table_name, *column_names)
  File "/usr/lib64/python2.7/site-packages/django/db/backends/base/schema.py", line 123, in _digest
    h = hashlib.md5()
ValueError: error:060800A3:digital envelope routines:EVP_DigestInit_ex:disabled for fips


 Is there a particular reason why MD5 is used here? Is there any harm in changing it to sh512 or something similar?

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/c8568650-33a8-49de-b86d-f6682d0e9f7d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Re: django.db.utils.OperationalError: server closed the connection unexpectedly

It's because you don't have PostgreSQL installed. The LitDB instructions say, among other things, "Make sure that you have a PostgreSQL database running and that you have permissions to create tables in that database".

The LitDB installation instructions are quite brief, which is probably fine for someone who knows Django already, but you're in for a rough ride. What operating system are you running? In Debian/Ubuntu you can install postgresql with "apt install postgresql". Are you executing manage.py as root?

Antonis Christofides  http://djangodeployment.com

On 2017-05-31 16:10, Bobby Paul wrote:
Dear Antonis,

Thank you very much for your quick response.
Sorry, I am newer in this field. I was trying to install LitDB (http://www.ikmb.uni-kiel.de/litdb)
I changed the settings as what your suggestion, but not happened.

with port number 5432, it showing
 Is the server running on host "localhost" (::1) and accepting
        TCP/IP connections on port 5432?
could not connect to server: Connection refused
        Is the server running on host "localhost" (127.0.0.1) and accepting
        TCP/IP connections on port 5432?

Is there any other settings i need to change?
Thanks and Regards
Bobby Paul


On Wednesday, May 31, 2017 at 5:14:29 PM UTC+5:30, Bobby Paul wrote:
Dear All,

I am getting this error message while trying to install psql database.

 File "setup.py", line 18, in <module>
    execute_from_command_line(['manage.py','migrate'])
  File "/usr/local/bin/lib/python2.7/site-packages/django/core/management/__init__.py", line 354, in execute_from_command_line
    utility.execute()
  File "/usr/local/bin/lib/python2.7/site-packages/django/core/management/__init__.py", line 346, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/bin/lib/python2.7/site-packages/django/core/management/base.py", line 394, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/usr/local/bin/lib/python2.7/site-packages/django/core/management/base.py", line 445, in execute
    output = self.handle(*args, **options)
  File "/usr/local/bin/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 93, in handle
    executor = MigrationExecutor(connection, self.migration_progress_callback)
  File "/usr/local/bin/lib/python2.7/site-packages/django/db/migrations/executor.py", line 19, in __init__
    self.loader = MigrationLoader(self.connection)
  File "/usr/local/bin/lib/python2.7/site-packages/django/db/migrations/loader.py", line 47, in __init__
    self.build_graph()
  File "/usr/local/bin/lib/python2.7/site-packages/django/db/migrations/loader.py", line 191, in build_graph
    self.applied_migrations = recorder.applied_migrations()
  File "/usr/local/bin/lib/python2.7/site-packages/django/db/migrations/recorder.py", line 59, in applied_migrations
    self.ensure_schema()
  File "/usr/local/bin/lib/python2.7/site-packages/django/db/migrations/recorder.py", line 49, in ensure_schema
    if self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor()):
  File "/usr/local/bin/lib/python2.7/site-packages/django/db/backends/base/base.py", line 162, in cursor
    cursor = self.make_debug_cursor(self._cursor())
  File "/usr/local/bin/lib/python2.7/site-packages/django/db/backends/base/base.py", line 135, in _cursor
    self.ensure_connection()
  File "/usr/local/bin/lib/python2.7/site-packages/django/db/backends/base/base.py", line 130, in ensure_connection
    self.connect()
  File "/usr/local/bin/lib/python2.7/site-packages/django/db/utils.py", line 98, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/usr/local/bin/lib/python2.7/site-packages/django/db/backends/base/base.py", line 130, in ensure_connection
    self.connect()
  File "/usr/local/bin/lib/python2.7/site-packages/django/db/backends/base/base.py", line 119, in connect
    self.connection = self.get_new_connection(conn_params)
  File "/usr/local/bin/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/base.py", line 176, in get_new_connection
    connection = Database.connect(**conn_params)
  File "/usr/local/bin/lib/python2.7/site-packages/psycopg2/__init__.py", line 130, in connect
    conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
django.db.utils.OperationalError: server closed the connection unexpectedly
        This probably means the server terminated abnormally
        before or while processing the request.
==========
DATABASES_DEFAULT = {

        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'litdb',
        'USER': 'root',
        'PASSWORD': '',
        'HOST': 'localhost',
        'PORT': '80',
}

How to sort this issue?

Kind Regards
Bobby Paul
--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/c367c3b4-502b-49ec-94e3-10a0433ccb99%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Re: django.db.utils.OperationalError: server closed the connection unexpectedly

Dear Antonis,

Thank you very much for your quick response.
Sorry, I am newer in this field. I was trying to install LitDB (http://www.ikmb.uni-kiel.de/litdb)
I changed the settings as what your suggestion, but not happened.

with port number 5432, it showing
 Is the server running on host "localhost" (::1) and accepting
        TCP/IP connections on port 5432?
could not connect to server: Connection refused
        Is the server running on host "localhost" (127.0.0.1) and accepting
        TCP/IP connections on port 5432?

Is there any other settings i need to change?
Thanks and Regards
Bobby Paul


On Wednesday, May 31, 2017 at 5:14:29 PM UTC+5:30, Bobby Paul wrote:
Dear All,

I am getting this error message while trying to install psql database.

 File "setup.py", line 18, in <module>
    execute_from_command_line(['manage.py','migrate'])
  File "/usr/local/bin/lib/python2.7/site-packages/django/core/management/__init__.py", line 354, in execute_from_command_line
    utility.execute()
  File "/usr/local/bin/lib/python2.7/site-packages/django/core/management/__init__.py", line 346, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/bin/lib/python2.7/site-packages/django/core/management/base.py", line 394, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/usr/local/bin/lib/python2.7/site-packages/django/core/management/base.py", line 445, in execute
    output = self.handle(*args, **options)
  File "/usr/local/bin/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 93, in handle
    executor = MigrationExecutor(connection, self.migration_progress_callback)
  File "/usr/local/bin/lib/python2.7/site-packages/django/db/migrations/executor.py", line 19, in __init__
    self.loader = MigrationLoader(self.connection)
  File "/usr/local/bin/lib/python2.7/site-packages/django/db/migrations/loader.py", line 47, in __init__
    self.build_graph()
  File "/usr/local/bin/lib/python2.7/site-packages/django/db/migrations/loader.py", line 191, in build_graph
    self.applied_migrations = recorder.applied_migrations()
  File "/usr/local/bin/lib/python2.7/site-packages/django/db/migrations/recorder.py", line 59, in applied_migrations
    self.ensure_schema()
  File "/usr/local/bin/lib/python2.7/site-packages/django/db/migrations/recorder.py", line 49, in ensure_schema
    if self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor()):
  File "/usr/local/bin/lib/python2.7/site-packages/django/db/backends/base/base.py", line 162, in cursor
    cursor = self.make_debug_cursor(self._cursor())
  File "/usr/local/bin/lib/python2.7/site-packages/django/db/backends/base/base.py", line 135, in _cursor
    self.ensure_connection()
  File "/usr/local/bin/lib/python2.7/site-packages/django/db/backends/base/base.py", line 130, in ensure_connection
    self.connect()
  File "/usr/local/bin/lib/python2.7/site-packages/django/db/utils.py", line 98, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/usr/local/bin/lib/python2.7/site-packages/django/db/backends/base/base.py", line 130, in ensure_connection
    self.connect()
  File "/usr/local/bin/lib/python2.7/site-packages/django/db/backends/base/base.py", line 119, in connect
    self.connection = self.get_new_connection(conn_params)
  File "/usr/local/bin/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/base.py", line 176, in get_new_connection
    connection = Database.connect(**conn_params)
  File "/usr/local/bin/lib/python2.7/site-packages/psycopg2/__init__.py", line 130, in connect
    conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
django.db.utils.OperationalError: server closed the connection unexpectedly
        This probably means the server terminated abnormally
        before or while processing the request.
==========
DATABASES_DEFAULT = {

        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'litdb',
        'USER': 'root',
        'PASSWORD': '',
        'HOST': 'localhost',
        'PORT': '80',
}

How to sort this issue?

Kind Regards
Bobby Paul

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/c367c3b4-502b-49ec-94e3-10a0433ccb99%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

value of checkbox aren't saved in the form

i am a beginner with Django. I don''t know what the problem with the value of checkbox. When i enter to the saved form the value of checkbox aren't save.The image is here . Please I need your help, I loose too much time on this.

This is my forms.py:

class BacktestForm(forms.ModelForm):

period_start = forms.DateField(initial=datetime.datetime.today().date() - datetime.timedelta(days=365+16), widget=forms.widgets.DateInput(format="%Y/%m/%d"), input_formats=["%Y/%m/%d"])
period_end = forms.DateField(initial=datetime.datetime.today().date() - datetime.timedelta(days=16), widget=forms.widgets.DateInput(format="%Y/%m/%d"), input_formats=["%Y/%m/%d"])
        
        market = forms.MultipleChoiceField(required=False,widget=CheckboxSelectMultiple, choices=MARKET_CHOICES)
        sector = forms.MultipleChoiceField(required=False,widget=CheckboxSelectMultiple, choices= MEDIA_CHOICES)
class Meta:
model = Parameters

This is my models.py:

class Parameters(models.Model):

user = models.ForeignKey(User)
title = models.CharField('title', max_length=100, default='', blank=True, help_text='Use an indicative name, related to the chosen parameters')
type = models.CharField('forecast type', choices=FORECAST_TYPES, max_length=20, default="backtest")

#input characteristics
price_1_min = models.FloatField('1. Price, min', default=0.1, validators=[MinValueValidator(0.1), MaxValueValidator(20000)])

def get_backtest_url(self):
return reverse('saved_backtest', kwargs={'pk': self.pk})


The save function in views.py:

 
        if request.method == 'POST':
if form.is_valid():
if 'save' in request.POST:
obj = form.save(commit= False)
obj.user = request.user
obj.type = "backtest"
obj.save()
messages.info(request, 'Saved!')
return redirect(obj.get_backtest_url())


The template for the saved form is :

 <div> {% if user.is_authenticated %}
{% if user.profile.is_active %}
                                     &nbsp; Saved from "Backtesting"
<ul>
{% for param in user.parameters_set.all %}
{% if param.type == "backtest" %}
                                                         <table style="width:100%">
                                                          <tr>
                                                           <th> Saved File </th>
                                                           <th> Created at </th>
                                                           
                                                          <tr> 
 
                                                           <td> <a href='{{param.get_backtest_url}}'>{{param.title}}  </a> </td>
  <td> {{param.created_at}} </td>
                                                           
         </tr>
        </table>
{% endif %}
{% endfor %}
</ul>

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/55e259b4-8986-41d0-849e-4fe809001ff0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.