Re: Queying 3 tables in Django

2023-05-13 Thread _M_A_Y_A_N_K_
You could follow the steps below.

   - Create a view function that takes the search parameter as a keyword
   argument.
  - Use the QuerySet object to filter the Skill table by the search
  parameter.
  - Use the prefetch_related() method to load the Recruitment objects
  associated with the Skill objects.
  - Return the Recruitment objects.

I mean something like this
def get_recruitments_by_skill(request, skill):
# Get the skills that match the search parameter.
skills = Skill.objects.filter(sk1=skill)

# Prefetch the recruitments associated with the skills.
skills.prefetch_related('recruitment')

# Return the recruitments.
return render(request, 'recruitments.html', {'skills': skills})


Thanks & Regards,
-
Mayank Tripathi
"Do what you can, with what you have, where you are -by Theodore Roosevelt"



On Sat, May 13, 2023 at 4:56 PM Oduwa Imade  wrote:

> Hello Guys! How do I write a model query in django python to get the User
> details(Recruitment) when i pass a search parameter( skill) to the Skill
> table?
>
> class Recruitment(models.Model):
> fname = models.CharField(max_length=50)
> lname = models.CharField(max_length=50)
> address = models.CharField(max_length=100)
> phone = models.IntegerField()
> email = models.CharField(max_length=50)
> password = models.CharField(max_length=30)
>
> class CV(models.Model):
> summary = models.TextField()
> f_key_REC = models.ForeignKey(Recruitment, related_name='cv',
> on_delete=models.CASCADE)
>
> class Skill(models.Model):
> sk1 = models.CharField(max_length=100, default=None)
> sk2 = models.CharField(max_length=100, default=None)
> sk3 = models.CharField(max_length=100, default=None)
> fk_sCV = models.ForeignKey(CV, related_name='skill',
> on_delete=models.CASCADE)
>
> --
> 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/c381af8c-e2f7-41b8-ae48-71f389a23459n%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/CALQo0B8sRLh-ivziMQSdLN_qqbgn4XyOQS%2BXNkWaH%2BzKm%3D376g%40mail.gmail.com.


Re: Django django_filters DateFilter customization

2021-01-22 Thread _M_A_Y_A_N_K_
Thanks Kasper,

I utilized the suggestion you shared, and implemented it with a custom
template tag, and now am able to restrict it.

[image: image.png]

Thanks & Regards,
-
Mayank Tripathi
Mo. +1 615 962 2128
"Do what you can, with what you have, where you are -by Theodore Roosevelt"
https://datascience.foundation/datascienceawards



On Fri, Jan 22, 2021 at 2:46 PM Kasper Laudrup 
wrote:

> Hi Maynak,
>
> On 22/01/2021 21.34, Mayank Tripathi wrote:
> > Hi All,
> >
> > I am look for a solution where I can restrict the user to select date
> > from current month only instead of selecting any other month or year.
> >
> > Currently user can select past month as well, have to restrict for
> > current month only in date picker.
> >
>
> It seems like the HTML date input field has attributes for setting the
> min and max value:
>
>
> https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/date#additional_attributes
>
> Setting these attributes to the first and last day of the month for the
> widget ought to work:
>
>
> https://docs.djangoproject.com/en/3.1/ref/forms/widgets/#django.forms.Widget.attrs
>
> Of course, you still need to ensure that the client doesn't send an
> invalid/unexpected date.
>
> I haven't tested this, but that's what I'd try to do at least.
>
> Hope that helps.
>
> 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/c56ecb88-6007-107c-e52f-c72f09f05f2a%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/CALQo0B_a2AF_oGB9MZxPhpiiKyhSRpLeiAgYqpwd_U3ynPeQMg%40mail.gmail.com.


Re: Django django_filters DateFilter customization

2021-01-22 Thread _M_A_Y_A_N_K_
Thanks Kasper,

Will try the suggested option.

Meanwhile, do you know how to get the documentation for danjo_filters
DateFilter() method, and want to know what all parameters it can accept.
Usually we do pass  field_name; lookup_expr; label , just curious if we
could pass *attrs *as we pass in forms.Modelform.
I did try checking the document from
https://django-filter.readthedocs.io/en/stable/ref/filters.html#datefilter,
but there its not mentioned.
Please direct me to the right direction.


Thanks & Regards,
-
Mayank Tripathi
Mo. +1 615 962 2128
"Do what you can, with what you have, where you are -by Theodore Roosevelt"
https://datascience.foundation/datascienceawards



On Fri, Jan 22, 2021 at 2:46 PM Kasper Laudrup 
wrote:

> Hi Maynak,
>
> On 22/01/2021 21.34, Mayank Tripathi wrote:
> > Hi All,
> >
> > I am look for a solution where I can restrict the user to select date
> > from current month only instead of selecting any other month or year.
> >
> > Currently user can select past month as well, have to restrict for
> > current month only in date picker.
> >
>
> It seems like the HTML date input field has attributes for setting the
> min and max value:
>
>
> https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/date#additional_attributes
>
> Setting these attributes to the first and last day of the month for the
> widget ought to work:
>
>
> https://docs.djangoproject.com/en/3.1/ref/forms/widgets/#django.forms.Widget.attrs
>
> Of course, you still need to ensure that the client doesn't send an
> invalid/unexpected date.
>
> I haven't tested this, but that's what I'd try to do at least.
>
> Hope that helps.
>
> 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/c56ecb88-6007-107c-e52f-c72f09f05f2a%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/CALQo0B-6Mk1uxGDCYPP2gMLnk6x%2B507e3vp_LPGaVi7iK1%2B%3D6g%40mail.gmail.com.


Re: Two models one form, or use generic CreateView

2021-01-07 Thread _M_A_Y_A_N_K_
You could use InlineFormSet, which is designed specially to handle such
problems. Refer to the documentations here
https://docs.djangoproject.com/en/3.1/topics/forms/modelforms/#inline-formsets


Here you could provide the primary model (in your case it will be
CUstomUser), and the secondary model (which will be Address).
Something similar to below.


from django.forms import inlineformset_factoryCustomerFormSet =
inlineformset_factory(CustomUser, Address, fields=('email',
'firstname', ..  'address','zipcode',))

  Hope this helps.


Thanks & Regards,
-
Mayank Tripathi
"Do what you can, with what you have, where you are -by Theodore Roosevelt"
https://datascience.foundation/datascienceawards



On Tue, Jun 9, 2020 at 7:36 AM The Sha  wrote:

> Hi
>
> I hava a problem in django, i have to models one is a CustomUser Model and
> the other is a Address model.
>
> The problem is that when i create a generic CreateView for the Address
> model and use a pk: url the address form wont get the instance of the users
> PK for adding a new address.
>
> my models look like this, Even though i pass the PK in the URL the
> CreateView does not understand that i want to add a address to user with
> id: 42 in this example. How can i solve this problem?
>
>
>
>
>
>
>
> The URL
>  path('/address', views.AddressCreateView.as_view(),
> name='Address-add'),
>
>
> *This is my view*
> class AddressCreateView(CreateView):
> model = Address
> template_name = 'members/address_form.html'
> success_url = reverse_lazy('MemberIndex')
> fields = ('CustomUser', 'address', 'zip_code', 'city', 'state',
> 'active')
>
>
> *The model*
> class CustomUser(AbstractBaseUser, PermissionsMixin):
> email = models.EmailField(_('email address'), unique=True)
> personal_Id = models.CharField(max_length=12, blank=False)
> first_name = models.CharField(_('first name'), max_length=30, blank=
> True)
> middle_name = models.CharField('middle name', max_length=30, blank=
> True)
> last_name = models.CharField(_('last name'), max_length=30, blank=True
> )
> is_staff = models.BooleanField(default=False)
> is_active = models.BooleanField(default=True)
> date_joined = models.DateTimeField(default=timezone.now)
> avatar = models.ImageField(upload_to='images', blank=True)
>
> def __str__(self):
> return self.email
>
> def full_name(self):
> return '%s %s %s' % (self.first_name, self.middle_name, self
> .last_name)
>
> USERNAME_FIELD = 'email'
> REQUIRED_FIELDS = []
>
>
> objects = CustomUserManager()
>
> class Address(models.Model):
> CustomUser = models.ForeignKey(CustomUser, on_delete=models.CASCADE)
> address = models.CharField(max_length=60, blank=False)
> zip_code = models.CharField(max_length=8, blank=False)
> city = models.CharField(max_length=30, blank=False)
> state = models.CharField(max_length=30, blank=False)
> active = models.BooleanField(name='active', default=True, editable=
> True)
> address_reg_date = models.DateTimeField(default=timezone.now)
> class Meta:
> verbose_name_plural = "Address"
>
> def __str__(self):
>  return self.address +', '+ str(self.zip_code) + ', ' + self.city
>
>
>
>
>
> --
> 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/d0d3596f-6c0e-4928-8e57-7eb5476821d3o%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/CALQo0B8n1%2B%3D9LzLBDdb-VeJjUc7vW92Cxjo4fc6bGzuPnHwRGw%40mail.gmail.com.


Re: Python-django project

2020-07-23 Thread _M_A_Y_A_N_K_
Interested

Thanks & Regards,
-
Mayank Tripathi
Mo. +1 615 962 2128
"Do what you can, with what you have, where you are -by Theodore Roosevelt"



On Thu, Jul 23, 2020 at 3:49 PM Himanshi Dhanwadhiya 
wrote:

> Interested
>
> On Tue, 21 Jul, 2020, 8:39 am learn code,  wrote:
>
>> Hi everyone,
>>
>> I am learning python and django, like to work on the projects to improve
>> more.If any one interested to join with me to work on the projects,plz send
>> me a email.
>>
>> --
>> 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/e7116e9b-9458-4f49-a638-135c4b5874e0o%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/CAK%2B6XsCzaXtAcCY_pKw%2Bc3n%3DJbB%2Beu3NF6wEbDDTYGwc6_wfiw%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/CALQo0B8gx3VOed-RDzGnLYFoBaPMcxzJ6Qj6Bs6Z9H38teRy8A%40mail.gmail.com.


Re: Help Me!!

2020-06-08 Thread _M_A_Y_A_N_K_
Do you already have a python code for StopWatch...? If so then you can
directly use that python code in your django view and send it to the HTML
page.
Playing with Button as Start / Stop can be done using HTML and (or)
JavaScript.

Let me know if you need help in python code for StopWatch.

Hope this helps.

Thanks & Regards,
-
Mayank Tripathi

On Mon, Jun 8, 2020 at 12:26 PM meera gangani 
wrote:

> Hello,
>
>   I want to create Stopwatch in django where, we provide One start
> button and that turned into stop button,
>it means when we click the start button that turns into
> a stop button.
>
> Please help me out!!
>
>
> Thanks in advance
> -Meera Gangani
>
> --
> 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/CANaPPPJr5o9CYHEYfgHuS-t9mMoGJ3K1tjg5FMwQa%3DWbir9QTQ%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/CALQo0B-UkS4hj2TmtzSw0Z0N9NJ14fMeW%2BhfZY5SBmBoAuyosQ%40mail.gmail.com.


Re: Can we use Database with Django without creating models

2020-05-25 Thread _M_A_Y_A_N_K_
Adding more details...
I did tried *inspectdb, *but having other different issues with this. Here
i want to purely use the legacy / existing database.

Thanks & Regards,
-
Mayank Tripathi
Mo. +1 615 962 2128
"Do what you can, with what you have, where you are -by Theodore Roosevelt"


On Mon, May 25, 2020 at 7:28 PM Mayank Tripathi 
wrote:

> Hi Team,
>
> I am trying to get options to connect to Database from Python-Django App.
> But here the requirement is I already have a Database setup (MySQL) with
> all required tables and fields.
> So am not willing to use models.py and create tables.
> Is there a way still i can use the tables... and still be able to do
> similar query which is done using ORM (i mean Django default querysets).
>
> Please suggest.
>
> --
> 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/ea4fdb96-0462-40ad-aec1-6bf1318cb0fd%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/CALQo0B-%3DH5wNd6KDp6TprZLDxLXBVX8gTo8EstQ7EGRkLcqvZA%40mail.gmail.com.


Re: Charts view function suggestions

2020-05-08 Thread _M_A_Y_A_N_K_
Hi Hajar,

Though you have multiple model, the main thing is to create a queryset.
Once you have a queryset (which can be from one model or multiple model)..
you should be able to use that queryset for Pie-Charts or any other charts.
Also try to use Django-Chart.js, which is much more easier i feel.

Hope this helps.
Also let know if you face any issue. You can share the queryset for which
you need charts.. then probably we can help then.

Thanks & Regards,
-
Mayank Tripathi
Mo. +1 615 962 2128
"Do what you can, with what you have, where you are -by Theodore Roosevelt"
https://datascience.foundation/datascienceawards



On Fri, May 8, 2020 at 5:20 PM hajar Benjat  wrote:

> Hello everyone how are you doing ?
>
> I need your suggestions > I have to use a specific models , and I want to
> do a  pie_chart view function based on this models , " but I don't know
> what to do I saw some view functions examples but they always use one class
> but here my classes a bit hard and I am really stack and I need your help "
>
> this is the models I have to use ,
>
> from django.db import models
>
> # Create your models here.
> class Country(models.Model):
> Country = models.CharField(max_length=100)
>
> def __str__(self):
> return '{} '.format(self.Country)
>
> class Reason(models.Model):
> Reason_cd = models.IntegerField(blank=True)
> Reason_NM = models.CharField(max_length=100, blank=True)
> def __str__(self):
> return '{}'.format(self.Reason_NM)
>
> class Mesure(models.Model):
> Mesure_cd = models.IntegerField(blank=True)
> Mesure_NM = models.CharField(max_length=100,blank=True)
>
> def __str__(self):
> return '{}'.format(self.Mesure_NM)
>
> class Client(models.Model):
> last_name = models.CharField(max_length=250)
> first_name = models.CharField(max_length=250)
> Adresse = models.CharField(max_length=560)
> city = models.CharField(max_length=100)
> code_postal = models.IntegerField()
> phone number = models.IntegerField(blank=True,null=True)
> mail = models.CharField(max_length=100)
>
> def __str__(self):
> return '{}, {}'.format(self.last_name,self.first_name)
>
> class Delivery_Agent(models.Model):
> last_name = models.CharField(max_length=250)
> first_name = models.CharField(max_length=250)
>
> def __str__(self):
> return '{}, {}  '.format(self.last_name,self.first_name)
>
> class Office(models.Model):
> office_cd = models.CharField(max_length=10)
> office_NM = models.CharField(max_length=50)
>
> def __str__(self):
> return '{}, {}  '.format(self.office_cd,self.office_NM)
>
> class Mail_item_Event(models.Model):
> mail_item_fid = models.CharField(max_length=36)
> Event_cd = models.IntegerField(auto_created=True,unique=True) #Event 
> code
> office_Evt_cd = models.ForeignKey(Office, on_delete=models.CASCADE, 
> related_name='office_Evt')
> Date_Evt = models.DateTimeField()
> Date_Capture = models.DateTimeField()
> Next_office = models.ForeignKey(Office, on_delete=models.CASCADE, 
> related_name='Next_office')
> def __str__(self):
> return '{}'.format(self.Event_cd)
>
> class Delivery_info(models.Model):
> mail_item_fid = models.OneToOneField(Mail_item_Event 
> ,on_delete=models.CASCADE)
> Event_cd = 
> models.OneToOneField(Mail_item_Event,on_delete=models.CASCADE,related_name="delivery_infor_event_cd")
> office_Evt_cd = models.ForeignKey(Office,on_delete=models.CASCADE, 
> related_name='office_Evt2')
> Date_Evt = models.DateTimeField()
> Agent_delivery_cd = 
> models.ForeignKey(Delivery_Agent,on_delete=models.CASCADE,related_name='agentDelivery')
> Signatory_NM = models.OneToOneField(Delivery_Agent, 
> on_delete=models.CASCADE, related_name='signatory')
> Raison_Non_Delivery_cd = 
> models.ForeignKey(Reason,on_delete=models.CASCADE, 
> related_name='raisonNonDelivery', blank=True)
> def __str__(self):
> return '{}, {} '.format(self.Signatory_NM,self.mail_item_fid)
>
> class mail_items(models.Model):
> mail_item_fid = 
> models.OneToOneField(Mail_item_Event,on_delete=models.CASCADE)
> Event_cd = 
> models.OneToOneField(Mail_item_Event,on_delete=models.CASCADE,related_name="mail_item_event_cd")
> office_Evt_cd = models.ForeignKey(Office,on_delete=models.CASCADE, 
> related_name='office_Ev')
> Date_Evt = models.DateTimeField()
> Country_origine = models.ForeignKey(Country, on_delete=models.CASCADE 
> ,related_name='paysOrigine')
> Country_destination = 
> models.ForeignKey(Country,on_delete=models.CASCADE,related_name='paysDestination')
> Expediteur = 
> 

Re:

2020-04-27 Thread _M_A_Y_A_N_K_
You can create a function based view  or class based view (views.py) where
you can have our own queryset to retrieve the data from database.
And pass the same into the html.

Thanks & Regards,
-
Mayank Tripathi
"Do what you can, with what you have, where you are -by Theodore Roosevelt"
https://datascience.foundation/datascienceawards



On Mon, Apr 27, 2020 at 7:11 PM fahad rasool 
wrote:

> How to retrieve data from database and display on web page ,example i want
> to display the details of the user on  a web page which he has entered in a
> form which is stored in database.
>
> --
> 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/CACqgSmA0Cjjx8S_SqeGF1wBDQggGAXszKdApOD45-1CPBPXG0g%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/CALQo0B_3KJ6Vhr0XYrRAZdMPEjyseAp8%2Brj%3DPrQhtJ96ngEQ4Q%40mail.gmail.com.


Re: Django - PrePopulate the Foreign Key on the web page, and use that id to save the model.

2020-04-12 Thread _M_A_Y_A_N_K_
Cool, thanks Antje.

Seems it is working now, the only thing is in Drop-down i will have the
Project Name for which the URL is rest of the PRojects are removed from
drop down.
Now will work to have pre-selected. As of now it will default display as
-- with only one required project name.

Thanks & Regards,
-
Mayank Tripathi
Mo. +1 615 962 2128
"Do what you can, with what you have, where you are -by Theodore Roosevelt"
https://datascience.foundation/datascienceawards



On Sun, Apr 12, 2020 at 3:07 AM Antje Kazimiers  wrote:

> Hi, I think in your view modulesView() you need to pass the project id to
> ModuleForm:
>
> ..
> else :
> form = ModuleForm(projectid)
> ..
>
> and then you need to overwrite the constructor of ModuleForm by adding an
> __init__ function:
>
>   def __init__(self, projectid=None, *args, **kwargs):
> super(ModuleForm, self).__init__(*args, **kwargs)
> if projectid is not None:
> self.fields['project'] = forms.ModelChoiceField(
> ...
> queryset=Project.objects.filter(id=projectid)
> )
>
> something like that. --Antje
>
> On Sunday, April 12, 2020 at 8:14:51 AM UTC+2, Mayank Tripathi wrote:
>>
>> Hi All,
>>
>> I am facing an issue, to pre-populate the Foreign Key on the web page.
>> Actually i have two models Projects and Modules.
>> To create a Module, one has to select the Project and go to Module page
>> for create it, but there the Project is not populated.
>>
>> Below are the details... Please guide me.
>>
>> *models.py*
>> class Project(models.Model):
>> name = models.CharField(max_length = 200, null = True)
>> startdate = models.DateTimeField()
>>
>> def __str__(self):
>> return self.name
>>
>> class Modules(models.Model):
>> project = models.ForeignKey(Project, null = True, on_delete =
>> models.SET_NULL)
>> modulename = models.CharField(max_length = 200, null = True)
>> modulestartdate = models.DateTimeField()
>>
>> def __str__(self):
>> return self.modulename
>>
>> *forms.py*
>> class ProjectForm(forms.ModelForm):
>> class Meta:
>> model = Project
>> fields = '__all__'
>>
>>
>> class ModuleForm(forms.ModelForm):
>> class Meta:
>> model = Modules
>> fields = '__all__'
>>
>> *views.py*
>> def projectView (request):
>> if request.method == 'POST':
>> form = ProjectForm(request.POST)
>> if form.is_valid():
>> form.save(commit=True)
>>
>> return render(request, 'budget/projectForm.html', {'form': form})
>>
>> else :
>> form = ProjectForm()
>> return render(request, 'budget/projectForm.html', {'form': form})
>>
>>
>> def modulesView (request, projectid):
>> project = Project.objects.get(pk=projectid)
>>
>> if request.method == 'POST':
>> form = ModuleForm(request.POST)
>> if form.is_valid():
>> form.save(commit=True)
>>
>> return render(request, 'example/modulesForm.html', {'form': form})
>>
>> else :
>> form = ModuleForm(instance=project)
>> return render(request, 'example/modulesForm.html', {'form': form})
>>
>> *urls.py*
>> path('testproject/', views.projectView, name='projectView'),
>> path('testprojectmodule//', views.modulesView,
>> name='modulesView'),
>>
>> in html forms for both Project and Modules... just using {{ form.as_table
>> }}.
>>
>> Now after createing the Project, i used the url as
>> http://127.0.0.1:8000/testprojectmodule/1/
>> then my Project should get pre-populated... as reached using the project
>> id which is 1 in this case, but i am getting full drop-down. Refer attached
>> image.
>> Either the Project should be pre-selected.. or can make it non-editable
>> either will work for me.
>>
>> Please help.
>>
>>
>> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/26744cb1-03e3-4189-a438-0b462013bb66%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/CALQo0B98Y_A0%2BJLZq%3DvoRVpTOm9kveqw%3DtRVhoXa9VJGPzvExQ%40mail.gmail.com.