Code for where member profiles are shown only to those who fit criteria

I want to create a website in the python programming language which I am still learning.

I want some advice for a website i’d like to launch, it will probably also have data saved to MySQL but i’m open to suggestions.

I want to create a website with members, kind of like a social friends website. It will be UK based, but anyone in the world can join. Members will register and need to login to access the website. They will create a profile, fill in their age, language, location, religion, education, social habits, hobbies, etc.

Members will also fill in a form

Profiles should be invisible to all except those that the member chooses to make them visible to. To this end, the member will also fill in a form detailing their ideal social friend. This form will contain mainly drop down or other pre-set option, say check box or something.

Example
Jillian is a woman aged 35, living in Glasgow, etc. etc. She fills in a form saying her profile should be visible to men aged 32 to 45 only, who have such a hobby, who speak such a language, who live in a certain geographical location, etc. etc.

Thus, the only people who should see Jillian’s profile are those who exactly fit her criteria.

Can anyone suggest how I could go about this? I was thinking maybe using Python ‘for’ loops with ‘continue’, but maybe there is a better option.

Thank you in advance.

Thus, the only people who should see Jillian’s profile are those who exactly fit her criteria.

Is it intentional (or e.g. a paid feature) that they’re shown Jillian’s profile, regardless of their own preferences?

Anyway, I don’t know how Tinder et al do it. But get a basic Django app running, and play with the User models. Add some application logic that lets users essentially create a filter, then when they request to view “social friends”, go through the sub list of users remaining after that filter, and remove them if their filter excludes the user asking to view them, and use one of the build it in Model Views to display that list of remaining users who made it through both filters.

There is not doubt huge scope for optimisations based on location, and dating preferences.

Thanks for the reply, James

There will be no paid features. And you will only see someone’s profile, if you also fit what they want.

It is actually the opposite to what dating sites do.They try to get you to see as many profiles as possible, because that is how they make their money.

Members on my site, will choose who sees their profiles, there will be a long list of ‘must have’s’ if need be.

So in this case, the other person who sees Jillian’s profile will also be someone who is seeking excactly what she is.

My website is unusual in that the member gets to choose who sees their profile, and it will only be shown to the other members who are seeking exactly what Jillian is.

I’d rather not use Laravel etc. I’d rather just code it, so I’m wondering what the best way to go about it will be.

Thank you again

Based on my knowledge, this isn’t actually something Python is good at.

I have done things like this in Python, and Python is decent for the back-end, but the most important parts are most easily written in html, javascript and SQL. I think the Python pathway this is more there for people who already know Python and don’t want to learn javascript and SQL.

If you want to write this kind of thing primarily learning Python, I believe Django is a good way to go. You can use sqalchemy to interact with a database without having to learn SQL. (But I think learning SQL is no harder than learning the sqalchemy library.) As @JamesParrott said, the first and most important step is to get a website up and running. If you settle for running it locally (and accessing it via localhost) that’s not too hard. From there you’ll want to experiment with the API requests that are send from the website to your backend. And with sending information between the backend and your database.

Regardless, the UK did make websites like this illegal not long ago. Online Safety Act 2023 is a bad[1] law, but it is the law. As soon as you’d get more than a certain number of users, you’ll be liable for a fine of up to £18 million. Just something to be aware of.


  1. as in evil ↩︎

I think you’ve misunderstood that - dating sites are only illegal in the UK if they do not prevent children from using them to access harmful material (assuming the specific site is not illegal in some other way).

I’m not a lawyer, but I’ve read the salient parts of the legislation. My take is, amongst other things (including more requirements on big social platforms and dedicated adult sites) in a nutshell, and to greatly over simplify, the OSA says websites hosting user generated content must i) risk assess the danger of children using your site to access harmful material posted by other users, and ii) if you think harmful material is likely to be posted, the only cast iron mitigation is some form of age verification.

Peter, thank you.

I will chew over what you said regarding Python and Mysql.

I’m surprised to hear about the illegaility of websites like this due to the Online Safety Act? Dating websites do operate in the UK. Besides, I plan on having each member who is verified. They will verify who they are at registration.

Any legalities, I will adhere to. Why would i be fined for a big membership? How is Ebay and Amazon and other social or dating sites with large memberships allowed to operate in the UK then?

Thank you for the input

Oh, so Peter meant the ‘child access’ thing, if that is the case, not to worry, as I only want verified members.

I was hoping someone here could tell me how to code the searches. I was thinking maybe loops with conditions, like ‘continue’ .. the searches could be saved by the members…Oh well

Thank you for your input

I was hoping someone here could tell me how to code the searches

I’m not a lawyer either, but I know from people who did the research and decided to take their websites down.
Any kind of private chat without enterprise-level age verification puts you legally at risk.
I get the impression META put their best lobbyists on it to write a law that look innocuous whilst still allowing them to shut down any new competition.

Wikipedia was/is seriously worried about their own position, though they’re currently watching the courts and not modifying their service in the UK (Wikimedia Foundation Challenges UK Online Safety Act Regulations – Wikimedia Foundation).

I didn’t say you were wrong when you said it was a “bad law”.

I realized there is a challenge in that your filters work in the opposite direction from normal. Instead of “all users who pass the filter of user X” you need “all users who’s filters pass the user Y”.

You need to encode those filters in your database in order for your website to work, and from there on I’m pretty sure you could get it to work in ‘pure’ SQL.

But I can see the perspective it would be easier to build the prototype in Python. You could then create a list of users in python. I would do this by creating a class

@dataclass
class User:
  id: int
  filters: list[Callable[[User], bool]]
  languages: set[Language]
  hobbys: list[str]

The filters field would be a little tricky to instantiate. But figuring out how to do that is almost synonymous with answering the question “how do I store filters in the database” or “what filters do I allow”, which are questions you need to answer anyway.

Once you have your list of users, you can get the matches by using

matches = [u for u in users if all(f(candidate) for f in u.filters)]

Performance would be a little poor if you have to fetch all users from your database for every query and convert them all into objects. But that’s not going to be an actual problem if you less than 10.000 users. And you can optimize your way around it in various ways.

You generally don’t want to write loops in SQL. So if you go with my original recommendation you’d kind of have to limit the filters users can have to a fixed set of N filters which the user can pick parameters for.
With the python solution you can allow users to assemble a list of filters or arbitrary length. (Though you’ll still have to standardise what those filters can look like.)