Re: Data lost by a migration for renaming a field

2018-09-08 Thread chen


On Sunday, September 9, 2018 at 12:48:52 AM UTC+8, Jason wrote:
>
> https://docs.djangoproject.com/en/1.11/ref/migration-operations/#alterfield
>
> There are AlterField and RenameField operations available with migrations, 
> but you probably have to include them in your custom migrations.  Reason 
> being, how would django know that you're just renaming a field and not 
> deleting it and adding a new field in its place?  In other words, how would 
> django know going from 
>
> text = models.TextField()
> to
> other_name = models.TextField()
>
> is a rename operation instead of remove and add new column?
>

Hi Jason,

Thanks for explaining. It makes sense. I'm also thinking it might be much 
helpful to detect the rename as much as possible and give warning message 
about developer has to modify the migration to rename field properly. 
Alternatively, instead of detecting potential rename by django framework 
itself, it should be also helpful to add an option to makemigrations to do 
a rename migration, e.g.

./manage makemigrations --rename-field app

This new option would be useful for the case of creating a dedicated 
migration just to rename a field.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/9103e0a3-1e2f-47a3-ba66-fd390cfee643%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to save multiple model form in one template?

2018-09-08 Thread Savvey Chauhan
First Create 3 Views For each form .
Second Create urls for all 3 views .
THiRD CHANGE ACTION URL ACCORDING TO VIEWS URL
ADD AJAX TO SUBMIT THE FORM
IF YOU WANT TO DISPLAY A TOAST MESSAGE USE TOASTR ON HTML PAGE.
eg :

 
  {% csrf_token %}

  First Name:
  


  Last Name:
  


  
  Gender:
  

Submit
  






$( "#target" ).submit(function( event ) {
  var form = $("form").serialize();
  $.ajax({
url: '',
data: form ,
success: function (data) {
toastr["success"]("New Student Added !")
}
  });
  event.preventDefault();
});


https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css";>

https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js";>
https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js";>



VIEWS.PY


def update(request):
fname =  request.GET.get('fname')
lname =  request.GET.get('lname')
gender = request.GET.get('gender')
student.objects.create(firstname=fname,lastname=lname,gender=gender)
return JsonResponse ({'Success':'Success'})








On Fri, Sep 7, 2018 at 7:26 PM Anthony Petrillo 
wrote:

> Here is an example. I've cut out some of the code, but I this will give
> you the general idea. Note, I move the data from the Day form in to the
> Classes table. But you could just save both sets of data to their
> respective tables if desired.
>
> in views.py
>
> class ClassesAddView(LoginRequiredMixin,View):
> classesFormClass = ClassesRegForm
> daysFormClass = DaysForm
> template_name = 'qing/classes.html'
>
> def get(self,request,role='NoRole'):
> classesForm = self.classesFormClass()
> context['form'] = classesForm
> daysForm = self.daysFormClass()
> context['daysform'] = daysForm
> return render(request,self.template_name, context)
>
> def post(self, request, *args, **kwargs):
> classesForm = self.classesFormClass(request.POST)
> daysForm = self.daysFormClass(request.POST)
> if classesForm.is_valid() and daysForm.is_valid():
> days = str(request.POST.getlist('days'))
> reference = request.POST['reference']
> classes = classesForm.save()
> classes = Classes.objects.get(reference=reference)
> classes.days = days
> classes.save()
> else:
> classesForm = self.classesFormClass(request.POST)
> context['form'] = classesForm
> daysForm = self.daysFormClass(request.POST)
> context['daysform'] = daysForm
> context['datavalid'] = False
> return render(request, self.template_name, context)
> return HttpResponseRedirect(reverse('classesadd',args=(role,)))
>
> in forms.py
>
> class ClassesForm(ModelForm):
> class Meta:
> model = Classes
> fields = ['reference','course','teachers',etc...]
>
> class DaysForm(forms.Form):
> OPTIONS = (
> ("Sunday", "Sunday"),
> ("Monday", "Monday"),
> ("Tuesday", "Tuesday"),
> ("Wednesday", "Wednesday"),
> ("Thursday", "Thursday"),
> ("Friday", "Friday"),
> ("Saturday", "Saturday"),
> )
> days = forms.MultipleChoiceField(widget=forms.CheckboxSelectMultiple,
>  choices=OPTIONS)
>
>
> On Friday, September 7, 2018 at 9:47:51 AM UTC-4, Akshay Gaur wrote:
>>
>> I think it would be easier to write out a custom form (without using your
>> model classes, just the fields that you will need for all the models) and
>> then in the save method for that form's view, you create model objects
>> using the fields in the POST request.
>>
>> On Friday, September 7, 2018 at 5:43:11 AM UTC-5, Django Lover wrote:
>>>
>>>
>>> I have one page, which I have to show three model form and three
>>> different submit button for each.
>>>
>>> My question is how I can save these three form individually?
>>>
>>> FOLLOWING IS CODE:-
>>>
>>> **form.py**
>>>
>>>
>>> class UserTaxesMultiForm(MultiModelForm):
>>>form_classes = {
>>>'user_tax_form': MyForm,
>>>'user_discount_form': DiscountForm,
>>>'user_shiping_form': ShipmentForm,
>>>}
>>>
>>> *Note- myForm, DiscountForm, ShipmentForm are model forms. like
>>> following-*
>>>
>>> class MyForm(forms.ModelForm):
>>>prefix = 'tax'
>>>class Meta:
>>>model = StUserTaxDetails
>>>fields = ('tax_name', 'tax_rate')
>>>
>>>tax_name = forms.CharField(max_length=10,
>>> widget=forms.TextInput(),
>>> required=True, label="tax name")
>>>
>>> tax_rate = forms.FloatField(required=True,  label="tax rate")
>>>
>>>
>>> error_messages  = {
>>>'required': _('fields are required.'),
>>>}
>>>
>>> def clean_title(self):
>>>return self.cleaned_data['tax_name']
>>>
>>> def clean(self):
>>>ta

Re: I created a table view based on django that loads the whole data and is now having performance issues

2018-09-08 Thread Savvey Chauhan
if you want to increase  data related performance , useselect_related
or  prefetch related


On Sat, Sep 8, 2018 at 11:35 PM xcode101  wrote:

> What do you mean by table view? More so how is data loaded?
>
> On Saturday, 8 September 2018 19:21:54 UTC+3, brajesh kumar wrote:
>>
>> I created a table view based on django that loads the whole data and is
>> now having performance issues..
>>
>> Any suggestion would be appreciated.
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/9981b39f-fce4-4db5-8f69-e55ae755e957%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

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


Re: I created a table view based on django that loads the whole data and is now having performance issues

2018-09-08 Thread xcode101
What do you mean by table view? More so how is data loaded?

On Saturday, 8 September 2018 19:21:54 UTC+3, brajesh kumar wrote:
>
> I created a table view based on django that loads the whole data and is 
> now having performance issues..
>
> Any suggestion would be appreciated.
>

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


Re: django install

2018-09-08 Thread soumyajit banerjee
use anaconda navigator. then you can start play in django.
https://conda.io/docs/user-guide/install/index.html

On Sat, Sep 8, 2018 at 7:56 AM gonzalo rodrigo pereyra <
gonzalorp12...@gmail.com> wrote:

> saludos. soy nuevo en el increible mundo de la programacion, primero
> comence leyendo mucho y me gusto python., asi que lo instale ( la version
> 3.6.5.)
> y me gusta mucho dibujar asi que me incline para hacer diseƱo de paginas
> con django. si no es mucha molestia me podrian ayudar a instalar el mismo.
> me quede trabado luego que instale pip.Desde ya muchas gracias desde
> Argentina un saludo enorme!!!
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/5e81-5ac1-47b2-8999-60f231d70a8a%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>


-- 
Soumyajit Banerjee
Tech Analyst
Infosys
m: 9903675354
w: www.infosys.com  e: soumyajit4...@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 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/CAG8c6EH44SSvCTr6bbugjj4cFdscFUp2OJXWBM8sptVaAqu%2BPg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Data lost by a migration for renaming a field

2018-09-08 Thread Jason
https://docs.djangoproject.com/en/1.11/ref/migration-operations/#alterfield

There are AlterField and RenameField operations available with migrations, 
but you probably have to include them in your custom migrations.  Reason 
being, how would django know that you're just renaming a field and not 
deleting it and adding a new field in its place?  In other words, how would 
django know going from 

text = models.TextField()
to
other_name = models.TextField()

is a rename operation instead of remove and add new column?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/8015df46-1146-4491-b788-e2cb291835c6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


does django pdf documentation has all of the existing functions and classes?

2018-09-08 Thread Amirhosein Majidi
does django pdf documentation has all of the existing functions and classes 
and modules of django framework?
I just wanted to know if I read that pdf documentation that has about 1900 
pages then i learned all about the django or not.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/f422036f-9cd9-4711-b59a-fa6937096dee%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


What is a standard practice to drop tables of an app in Django?

2018-09-08 Thread Jae Pil Choi
I'm asking this on the official Django community after I asked on 
Stackoverflow because I still don't know what is the best practice for this 
particular action. 

(Original Question on Stackoverflow here 
:
 
What is Django commend equivalent to Rails' $ rails db drop)

My scenario goes as follow: 

1. I create 2 model class objects, Post, Product in models.py 
2. Post has 2 attributes: post_title, post_text. Product has its own but 
that's irrelevant. 
3. I make migrations and migrate. 
4. Then I go to /admin of my page and add some rows both on Post and 
Product. 

5. Now I remember that I I forgot to add an attribute post_author on Post 
and adds it in models.py
6. If I make migrations, Django warns me that already existing rows needs 
default values since they don't have this new attributes. 
7. I don't want any post without an author so I want to drop this existing 
rows and make it all again. 
8. However, I don't want to lose any Product rows already created. 


Here's the question: How do I drop ONLY Post table leaving Product and my 
Superuser intact? 

Original Stackoverflow post suggests manually removing db.sqlite3 file and 
migrations files but I really don't think this is the way to go and there 
must be some best practice or commend for this since Django is already at 
2.1.

If not, I think there must be a good reason not to have one and I want to 
know why. 



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


Data lost by a migration for renaming a field

2018-09-08 Thread chen
Hi,

I have a model which contains a BooleanField. I changed its name to a new 
one and updated help text as well. django generates operations RemoveField 
and AddField  in sequence for those changes. As a result of running this 
migration, original data is lost. I was confused by this behavior why 
django does not generate an operation to just rename the field by executing 
ALTER TABLE. Renaming a database field name is a common task during 
development, I think django should handle this properly without developer's 
extra work to migrate data (but probably SQLite could be an exception).

I actually did nothing special to make that migration. django version is 
1.11.13 and database backend is mariadb.

Any idea about this issue?

Thanks.

Regards,
Chenxiong Qi

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/847a9c72-7b7b-4eca-9624-989340ee82f9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


I created a table view based on django that loads the whole data and is now having performance issues

2018-09-08 Thread brajesh kumar
I created a table view based on django that loads the whole data and is now 
having performance issues..

Any suggestion would be appreciated.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/a1438251-50b1-4a61-9413-142f5fe084ab%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Online Judge.

2018-09-08 Thread Kasper Laudrup

Hi Razibul

On 08/09/2018 13.03, Md. Razibul Hasan Mithu wrote:

I want to make custom. Sometimes it will work locally without any
internet.



You should be able to run Matt Godbolts excellent compiler explorer 
locally, although that is not written in Python and I haven't tried 
running it locally.


https://github.com/mattgodbolt/compiler-explorer

But it's not really clear what you trying to achieve?

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 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/d2251638-56cc-c401-c22b-a829f7f67063%40stacktrace.dk.
For more options, visit https://groups.google.com/d/optout.


Re: Django for desktop app development

2018-09-08 Thread Jani Tiainen
Hi.

Even django is a web app development framework you can use some parts if it
to develop desktop apps.

But as pointed out you might get much further with developing api with
django and use that api in your desktop or mobile app.

la 8. syysk. 2018 klo 5.27 Muhammad Dilshad Khaliq <
dilshadkhaliq...@gmail.com> kirjoitti:

> I am final year student of software engineering.My final year project is
> about fee management system where student submit fee online and
> administrator use this system for managing fee and scholarship of student
> and notifying them about their any issue.So can i  make web based
> application or desktop application for administration site and notify
> student through mobile application.?*Is it good idea to use Django for
> desktop application?*
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To 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/199c0ed7-ce95-42e4-b391-462a491c22fe%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

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


Re: Django for desktop app development

2018-09-08 Thread Jason
well, django is a web application, so its definitely not suitable for 
making a standalone desktop application that you install and run.  Its 
meant to run on a server, handling HTTP requests and processing the data 
and returning a response.  That doesn't run in a desktop container 
application

however, if you're referring to an API that can be used both by desktop 
browsers as well as mobile devices or applications, then yes indeed, django 
is an excellent option for 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 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/a529d0a2-58a0-45db-a5b8-df0b83a35228%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Different results of running pure SQL query from Django and from PGAdmin

2018-09-08 Thread Jason
Hard to say what's happening without any 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 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/074e9571-0f6d-462b-b3be-7abb2fc72c6f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Is it possible to make form inside form

2018-09-08 Thread Md.iftequar iqbal
I an trying to make a model form which has foreign key of ohter model form.
Just like any management application

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To 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/012a64ed-d566-4075-93a8-d71a62bf4347%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Online Judge.

2018-09-08 Thread Md. Razibul Hasan Mithu
I want to make custom. Sometimes it will work locally without any
internet.

On Thu, Sep 6, 2018 at 5:42 PM  wrote:

> You can use third_party api's for compiling the code, instead of spending
> time on this.
>
> https://www.hackerearth.com/docs/wiki/developers/v3/
>
> On Thursday, September 6, 2018 at 12:19:07 PM UTC+5:30, Md. Razibul Hasan
> Mithu wrote:
>>
>> I want to make an *Online Judge System*. That system runs* C/C++* code
>> and Take output using some inputs. But Problem is how can I run a code *Using
>> Python* Language and take all output especially runtime and memory for
>> making all verdict like *Wrong answer, TLE, MLE. *
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/2bc5dff2-5fe0-4ac4-9fbe-41243c199dce%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

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