Send an email alert whenever newly created profile matches to his search term. I have two module recruiter and seeker. Recruiter can posted their jobs and Seeker can posted their profile. If recruiter searches the seeker's profile based on city name, keyskills,industry type etc.. The searched result can be saved because for future use. If any new seeker's profile matches that searched result which is saved previously it automatically send email to recruiter. This alert has been send everytime when new seeker can matched that recruiter search terms.
Recruiter table
class jobs(models.Model):
user = models.ForeignKey(User)
title = models.CharField(max_length=100)
jobsummary = models.TextField()
industry = models.CharField(max_length=100)
functionalarea = models.CharField(max_length=100)
min_exp = models.IntegerField(default=0)
max_exp = models.IntegerField(default=0)
class employerkeyskills(models.Model):
user = models.ForeignKey(User)
job=models.ForeignKey(jobs, unique=False)
keyskills=models.CharField(max_length=50)
class RecSaveSearch(models.Model):
user = models.ForeignKey(User)
employer=models.ForeignKey(User,unique=False)
searchname=models.CharField(max_length=100,blank=True)
savedsearch=models.CharField(max_length=400, blank=True)
Jobseeker Profile Table
class JSPersonal(models.Model):
user = models.ForeignKey(User)
name=models.CharField(max_length=100, blank=True, null=True)
email = models.EmailField(max_length=100, blank=True, null=True)
city = models.CharField(max_length=100, blank=True, null=True)
work_expyears = models.CharField(max_length=100, blank=True, null=True)
work_expmonths = models.CharField(max_length=100, blank=True, null=True)
salaryrange = models.CharField(max_length=50, blank=True, null=True)
industry = models.CharField(max_length=100, blank=True, null=True)
class JSSkills(models.Model):
user = models.ForeignKey(User)
skill = models.CharField(max_length=100, blank=True, null=True)
version = models.CharField(max_length=100, blank=True, null=True)
lastused = models.CharField(max_length=100, blank=True, null=True)
skillyear = models.CharField(max_length=100, blank=True, null=True)
skillmon = models.CharField(max_length=100, blank=True, null=True)
Related
I have a two models, Person and Video.
Below viewset allows me all methods like POST, PATCH, DELETE, GET.
class PersonViewSet(viewsets.ModelViewSet):
queryset = apis_models.Person.objects.all()
serializer_class = apis_serializers.PersonSerializer
permission_classes = [HasPermPage]
Video model is associated with person model through Target model which is my main problem. Each person has few videos.
Now what I need is when I do "/person/{id}/" I should get person details along with all videos details it associated with.
Please let me know what change needs to be done to above ViewSet.
Models and Serializer:
class Video(DFModel):
source = models.ForeignKey(Source, models.DO_NOTHING)
creator = models.ForeignKey(
Creator, models.DO_NOTHING, blank=True, null=True)
title = models.CharField(max_length=500)
views = models.IntegerField(blank=True, null=True)
likes = models.IntegerField(blank=True, null=True)
dislikes = models.IntegerField(blank=True, null=True)
tags = models.TextField(blank=True, null=True)
upload_date = models.DateTimeField(blank=True, null=True)
page_url = models.TextField(blank=True, null=True)
video_url = models.TextField(blank=True, null=True)
thumb_url = models.TextField(blank=True, null=True)
sfw = models.BooleanField(blank=True, null=True)
category = models.CharField(max_length=20, blank=True, null=True)
reviewed = models.TextField(blank=True, null=True)
severity = models.CharField(max_length=10, blank=True, null=True)
origin = models.CharField(max_length=20, blank=True, null=True)
organization_id = models.IntegerField(blank=True, null=True)
created_at = models.DateTimeField(auto_now_add=True, blank=True, null=True)
class Person(models.Model):
name = models.CharField(unique=True, max_length=45)
nationality = models.CharField(max_length=50, blank=True, null=True)
profession = models.CharField(max_length=50, blank=True, null=True)
avatar = models.CharField(max_length=100, blank=True, null=True)
active_scraping = models.BooleanField(blank=True, null=True)
vuln_score = models.FloatField(blank=True, null=True, default=None)
reviewed = models.TextField(blank=True, null=True)
created_at = models.DateTimeField(auto_now_add=True, blank=True, null=True)
class Target(DFModel):
person = models.ForeignKey(
Person, models.DO_NOTHING, blank=True, null=True)
video = models.ForeignKey(
'Video', models.DO_NOTHING, blank=True, null=True)
reviewed = models.TextField(blank=True, null=True)
created_at = models.DateTimeField(auto_now_add=True, blank=True, null=True)
class Meta:
db_table = 'target'
class PersonSerializer(CustomSerializer):
class Meta:
model = apis_models.Person
fields = '__all__'
class TargetSerializer(CustomSerializer):
class Meta:
model = apis_models.Target
fields = '__all__'
extra_fields = ['monthly_growth', 'vulnerablility_score']
class VideoSerializer(CustomSerializer):
source = SourceSerializer(read_only=True)
creator = CreatorSerializer(read_only=True)
class Meta:
model = apis_models.Video
fields = '__all__'
It looks like you have a ManyToMany relation between Person and Video, so, I suggest you to change your models to be like:
class Person(models.Model):
name = models.CharField(unique=True, max_length=45)
nationality = models.CharField(max_length=50, blank=True, null=True)
profession = models.CharField(max_length=50, blank=True, null=True)
avatar = models.CharField(max_length=100, blank=True, null=True)
active_scraping = models.BooleanField(blank=True, null=True)
vuln_score = models.FloatField(blank=True, null=True, default=None)
reviewed = models.TextField(blank=True, null=True)
created_at = models.DateTimeField(auto_now_add=True, blank=True, null=True)
videos = models.ManyToManyField(Video, through='Target', related_name="people") # Field that will have the videos of a Person
Once you have that, I suggest you to change your PersonSerializer object to be:
class PersonSerializer(CustomSerializer):
videos = VideoSerializer(source='videos', many=True)
class Meta:
model = apis_models.Person
fields = '__all__'
If you can't change your models to support ManyToMany fields I suggest you to do the following:
class Person(models.Model):
name = models.CharField(unique=True, max_length=45)
nationality = models.CharField(max_length=50, blank=True, null=True)
profession = models.CharField(max_length=50, blank=True, null=True)
avatar = models.CharField(max_length=100, blank=True, null=True)
active_scraping = models.BooleanField(blank=True, null=True)
vuln_score = models.FloatField(blank=True, null=True, default=None)
reviewed = models.TextField(blank=True, null=True)
created_at = models.DateTimeField(auto_now_add=True, blank=True, null=True)
def videos(self):
return Video.objects.filter(
id__in=Target.objects.filter(person=self).values('video')
)
And use the same serializer I used in the first part of the answer.
I have two tables Customer and Subscription in which Customer has the list of customers and Subscription contains the Customer and Packages.
In the customer list i want to show how many packages each customer has.
Subscription Model
class Subscription(models.Model):
client = models.ForeignKey(Customer, on_delete=models.SET_NULL, blank=True, null=True, related_name="subscriptions")
package = models.ForeignKey(Package, on_delete=models.SET_NULL, blank=True, null=True)
valid_start_date = models.DateTimeField()
valid_end_date = models.DateTimeField()
usage_count = models.IntegerField(null=True)
status = models.CharField(max_length=20)
transaction = models.BigIntegerField(blank=True, null=True, default=0)
created_at = models.DateTimeField()
updated_at = models.DateTimeField()
Customer Model
class Customer(AbstractBaseUser):
first_name = models.CharField(max_length=250, blank=True, null=True)
last_name = models.CharField(max_length=250, blank=True, null=True)
email = models.EmailField(unique=True, blank=True, null=True)
mobile_number = models.BigIntegerField(blank=True, null=True)
password = models.CharField(max_length=1000, blank=True, null=True)
gender = models.CharField(max_length=10, blank=True, null=True)
profile_picture = models.ImageField(upload_to="user_data/profile_picture", blank=True)
address = models.CharField(max_length=500, blank=True, null=True)
country = models.ForeignKey(Countries, on_delete=models.SET_NULL, blank=True, null=True)
state = models.ForeignKey(States, on_delete=models.SET_NULL, blank=True, null=True)
city = models.ForeignKey(Cities, on_delete=models.SET_NULL, blank=True, null=True)
pincode = models.IntegerField(blank=True, null=True)
number_of_logins = models.IntegerField(blank=True, null=True)
is_active = models.BooleanField(default=True)
created_at = models.DateTimeField(blank=True, null=True)
updated_at = models.DateTimeField(blank=True, null=True)
USERNAME_FIELD = "email"
Expected Result : I want to show the package field data from Subscription Model into the list of Customer model.
name - no. - emaiId- pakages_subbed
customer1 - mobile - email - package1,package2
customer2 - mobile - email - package4,package1
Actual Result : Only Customer field data
You need to use annotate in your queryset much as here
I think
query = Customer.objects.annotate(subscription_count=Count('subscriptions'))
ought to do it (with the count available as object.subscription_count for any object retrieved from this query)
This is just one database query, returning only Customer objects, whereas {{ customer.subscriptions.all|length }} will be a lot of them (and will probably also retrieve all the Subscription objects just to count them).
If you wanted greater access to the Subscription and Package objects you could do
Subscription.objects.all().order_by("client__id", "package__name")...
(I made up "package__name") which should get you the subscriptions grouped firstly by customer and then ordered by package name for each customer.
I am creating a Django web based application for freelancers ,that they would be paid for number of hours they have worked on a project and also a weekly report is to be generated for weekly work and for that i need to work with time stamps so how do i implement it?
I want to create a button of start timer and stop timer, which records the time stamps of start timer and end timer?
I have a User model which is extended to Freelancer and person who hires Freelancer. How do i implement this?
Where do i edit the model of time stamps?
I have this model
from django.db import models
from django.contrib.auth.models import AbstractUser
class User(AbstractUser):
is_freelancer = models.BooleanField('Freelancer status', default=False)
is_hirer = models.BooleanField('Hirer status', default=False)
class Freelancer(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
hourly_rate = models.PositiveIntegerField(default=10)
education = models.TextField(default='asia')
professional_bio = models.TextField(blank=True, null=True)
professional_title = models.TextField(blank=True, null=True)
location = models.CharField(max_length=10, blank=True, null=True)
Address = models.CharField(max_length=100, blank=True, null=True)
city = models.CharField(max_length=100, blank=True, null=True)
postal_code = models.PositiveIntegerField(blank=True, null=True)
country = models.CharField(max_length=100, blank=True, null=True)
class Hirer(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
hourly_budget = models.PositiveIntegerField(blank=True, null=True)
project_title = models.CharField(max_length=100, default='hi')
project_description = models.TextField(blank=True, null=True)
job_category = models.CharField(max_length=100)
professional_bio = models.TextField(blank=True, null=True)
professional_title = models.TextField(blank=True, null=True)
location = models.CharField(max_length=10, blank=True, null=True)
Address = models.CharField(max_length=100, blank=True, null=True)
city = models.CharField(max_length=100, blank=True, null=True)
postal_code = models.PositiveIntegerField(blank=True, null=True)
country = models.CharField(max_length=100, blank=True, null=True)
This question is a bit broad, and I'm not really sure what it has to do with timestamps. But you might think about an "TimeWorked" model with foreign keys to both hirer and freelancer:
class TimeWorked(models.Model):
hirer = models.ForeignKey('Hirer', on_delete=models.CASCADE)
freelancer = models.ForeignKey('Freelancer', on_delete=models.CASCADE)
rate = models.IntegerField()
start_time = models.DateTimeField(auto_now_add=True)
end_time = models.DateTimeField(null=True, blank=True)
so you can create an instance of this class at the start of a block of time, then at the end fill in the end_time; then you can easily query the total amount of time worked for a job, and calculate the total to bill.
(Note you might want to rethink your models a bit, especially separating the project details from the hirer, otherwise each hirer can only ever create a single project.)
My understanding is that since Django 1.5, Custom User Models are possible but not neccesary. In fact, Greenfeld and Roy argue in "Two Scoops of Django" that sometimes (like for creating a third party package) "Profile" models are still the way to go.
Since getProfile() has been removed however, I don't know how to target my Profile data in template. Because:
{{ request.user.get_profile.id }}
no longer produces any data, I've tried:
{{ request.user.userprofile.id }}
but that doesn't produce a value either.
So my question is, given the following model:
class UserProfile(models.Model):
user = models.ForeignKey(settings.AUTH_USER_MODEL, unique=True, null=True, on_delete=models.SET_NULL)
fullname = models.CharField(max_length=64, unique=False)
company = models.ForeignKey(ClientList, blank=False, null=True, db_column='client', on_delete=models.SET_NULL)
position = models.CharField(max_length=64, unique=False, blank=True, null=True)
egroup = models.CharField(max_length=50, choices=EMP_GROUP_CHOICES)
address1 = models.CharField(max_length=130, unique=False, blank=True, null=True)
address2 = models.CharField(max_length=30, unique=False, blank=True, null=True)
city = models.CharField(max_length=64, unique=False, blank=True, null=True)
state = models.CharField(max_length=64, unique=False, blank=True, null=True)
zipcode = models.CharField(max_length=15, unique=False, blank=True, null=True)
phone = models.CharField(max_length=15, unique=False, blank=True, null=True)
extension = models.CharField(max_length=15, unique=False, blank=True, null=True)
hphone = models.CharField(max_length=15, unique=False, blank=True, null=True)
mobile = models.CharField(max_length=15, unique=False, blank=True, null=True)
fax = models.CharField(max_length=15, unique=False, blank=True, null=True)
notes = models.TextField(max_length=2000, blank=True, null=True)
email = models.EmailField()
User.profile = property(lambda u: UserProfile.objects.get_or_create(user=u)[0])
def __str__(self):
return u'%s' % self.fullname
class Meta:
ordering = ['fullname']
class Admin:
pass
how do I get the userprofile.id in the template?
(note: not really relevant but the user object still explicity uses a foreign key in order to preserve the "on_delete" parameter)
To store user profile, it is recommended to use OneToOneField instead of ForeignKey with unique=True. Although they are the equivalent.
Once you set the relation to OneToOneField, you can retrieve the userprofile id by using the following query: user.userprofile.id
If you decide to use ForeignKey with unique=True, you can still retrieve it using the following queryset: user.userprofile_set.first()
Reference: https://docs.djangoproject.com/en/dev/topics/auth/customizing/#extending-the-existing-user-model
How is "translation" for following query to django queryset?
SELECT guid FROM feedme_feeditem
WHERE feed_id IN
(SELECT id FROM feedme_feed WHERE country_id IN
(SELECT id FROM feedme_country WHERE name='NL'))
models.py
class Country(models.Model):
name = models.CharField(max_length=250, blank=True)
class Category(models.Model):
name = models.CharField(max_length=250, blank=True)
slug = models.SlugField(blank=True, null=True, editable=False)
user = models.ForeignKey(User, blank=True, null=True)
country = models.ForeignKey(Country, blank=True, null=True)
class Feed(models.Model):
link = models.CharField(blank=True, max_length=450)
url = models.CharField(blank=True, max_length=450)
title = models.CharField(blank=True, null=True, max_length=250)
category = models.ForeignKey(Category, blank=True, null=True)
user = models.ForeignKey(User, blank=True, null=True)
last_update = models.DateField(blank=True, null=True, editable=False)
country = models.ForeignKey(Country, blank=True, null=True)
class FeedItem(models.Model):
title = models.CharField(max_length=350, blank=True)
link = models.URLField(blank=True)
content = models.TextField(blank=True)
feed = models.ForeignKey(Feed, blank=True, null=True)
read = models.BooleanField(default=False)
guid = models.CharField(max_length=255)
pub_date = models.DateTimeField()
To make more simple I already tried add country = models.ForeignKey(Country, blank=True, null=True) to FeedItem class but does't work how i expected.
guids = FeedItem.objects.filter(feed__country__name = 'NL')