accessing foreign key value in views.py

2017-05-18 Thread Amisha Hans
Hey , 

I am facing a lot of issues regarding this foreign key !.

Scenario is a s follows :-

models.py

class ComponentDeprecation(models.Model):
row_id = models.IntegerField(primary_key=True)
component = models.ForeignKey('SsComponents', db_column='component')
submitter = models.CharField(max_length=12)
description = models.CharField(max_length=4000)
deprecation_date = models.DateField()
submitted_date = models.DateTimeField()
deprecated_by = models.CharField(max_length=12, blank=True, null=True)
deprecated_date = models.DateTimeField(blank=True, null=True)

class Meta:
managed = False
db_table = 'component_deprecation'


class SsComponents(models.Model):
component = models.CharField(primary_key=True, max_length=40)
ddts_class = models.CharField(max_length=20)
vob = models.CharField(max_length=20)
vob_rel_path = models.CharField(max_length=30)
owner = models.CharField(max_length=16, blank=True, null=True)
comp_main_branch = models.CharField(max_length=60, blank=True, 
null=True)
starting_version = models.CharField(max_length=10, blank=True, 
null=True)
include_list = models.CharField(max_length=60, blank=True, null=True)
other_list = models.CharField(max_length=60, blank=True, null=True)
created_by = models.CharField(max_length=16)
created_date = models.DateField()
comp_type = models.CharField(max_length=3, blank=True, null=True)
lifecycle = models.CharField(max_length=20, blank=True, null=True)
description = models.CharField(max_length=4000, blank=True, null=True)
component_approval = models.ForeignKey(ComponentApproval, blank=True, 
null=True)
component_deprecation = models.ForeignKey(ComponentDeprecation, 
blank=True, null=True)
migrated = models.NullBooleanField()
migrated_date = models.DateField(blank=True, null=True)
last_updatetime = models.DateField(blank=True, null=True)

class Meta:
managed = False
db_table = 'ss_components'

views.py 

def lc_depr_detail_form(request):
'''
Returns the Fields in the form of List containing Dictionary to be 
rendered to HTML Page for Deprecate Report.
'''
user_name = request.META['REMOTE_USER']
#Fetching the field values from the HTML Page
component = request.POST.get('comp')
submitter = request.POST.get('submitter')
submitted_date = request.POST.get('sub_date')
deprecated_by = request.POST.get('dep_by')
deprecated_date = request.POST.get('dep_date')
stri = ""
#Putting the field  values in a string variable
if(component and component!= "None"):
comp1= component.replace("*", ".*")
stri=stri+" ,component=r'^%s$'" % (comp1)
if(submitter and submitter!= "None"):
submitter1=submitter.replace("*", ".*")
stri=stri+" ,submitter__regex=r'^%s$'" % (submitter1)
if(submitted_date and submitted_date!= "None"):
sub_date1=submitted_date.replace("*", ".*")
stri=stri+" ,submitted_date__regex=r'^%s$'" % (sub_date1)
if(deprecated_by and deprecated_by!= "None"):
dep_by1=deprecated_by.replace("*", ".*")j
stri=stri+" ,deprecated_by__regex=r'^%s$'" % (dep_by1)
if(deprecated_date and deprecated_date!= "None"):
dep_date1=deprecated_date.replace("*", ".*")
stri=stri+" ,deprecated_date__regex=r'^%s$'" % (dep_date1)
#Substituting the first comma with a space
data= re.sub(r',',"",stri,1)
#Checking when no data is Entered in the Form
if (data == ''):
return render(request, 
'lc_depr.html',{'user':user_name,'message':'Please provide atleast one 
Input','page':r'help/home.html'})

details="ComponentDeprecation.objects.filter(%s).order_by('-deprecated_date').values('component','deprecated_by','deprecated_date')"
 
% (data)
print details
#Evaluates the details as a Python Expression
details_list = eval(details)
print details_list
#Checking if the list is empty due to Wrong data Input by the User
if not details_list:
return render(request, 
'lc_depr_report.html',{'user':user_name,'message':'Oops! Couldnot figure 
out what you were searching for.Please recheck the inputs provided for the 
query','page':r'help/home.html'})
else:
return render(request, 
'lc_depr_report.html',{'user':user_name,'details_list':details_list,'page':r'help/home.html'})

 

i am getting this error: related field got invalid lookup: regex component 
only 
i dont know how to access the value of component .. for other fields no 
error is comming .




-- 
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.c

Setting the Date Format in the input fields

2017-05-18 Thread Amisha Hans
The default format is :
 
-MM-DD HH:MM:SS

i want it as /MM/DD HH:MM:SS for all the inputs ...
 
outputing in the same format was easy : using date and time filters 
 please help me out



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


Django Inner Join Queryset where there is no foreign key relation between two tables

2017-07-09 Thread Amisha Hans


down votefavorite 


Please Help ! I Want to know the inner join Queryset for the below 
mentioned raw oracle Query : -

select PubEv.published_date , PubEv.published_by ,PubEv.publish_by ,
PubC.component,PubC.comp_version,PubC.publish_id from PubEv inner join PubC 
on PubC.publish_id = PubEv.publish_id where PubC.target_branch = 
'polaris_dev' and PubC.component = 'aaa' order by PubEv.published_date desc;

And the models mentioned in the django project are as follows:-

class PubEv(models.Model):
vob = models.CharField(max_length=20)
target_branch = models.CharField(max_length=60)
publish_id = models.IntegerField(primary_key=True)
target_branch_label = models.CharField(max_length=50, blank=True, null=True)
main_release = models.CharField(max_length=10, blank=True, null=True)
published_by = models.CharField(max_length=16)
published_date = models.DateTimeField()
publish_ddts = models.CharField(max_length=10)
unpublished = models.CharField(max_length=1)
changeset = models.ForeignKey('CcChangesets')

class Meta:
managed = False
db_table = 'publish_events'
class PubC(models.Model):
publish_id = models.IntegerField(primary_key=True)
vob = models.CharField(max_length=20)
target_branch = models.CharField(max_length=60)
component = models.CharField(max_length=40)
comp_version = models.CharField(max_length=40)

class Meta:
managed = False
db_table = 'publish_contents'

-- 
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/c3206253-0f17-4eb7-8df0-6da0bc3129c7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.